From 6409d341459ac5d9250460c2cc44d8b50eb17d25 Mon Sep 17 00:00:00 2001 From: sean Date: Mon, 17 Oct 2022 16:34:14 +0200 Subject: [PATCH] Fix: Preallocate every buffer --- src/fastgltf.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/fastgltf.cpp b/src/fastgltf.cpp index 740b9f96d..6881e2d5b 100644 --- a/src/fastgltf.cpp +++ b/src/fastgltf.cpp @@ -176,7 +176,7 @@ std::tuple fg::glTF::decodeUri(std: DataSource source = {}; source.mimeType = getMimeTypeFromString(uri.substr(5, index - 5)); source.bytes = std::move(uriData); - return std::make_tuple(Error::None, source, DataLocation::VectorWithMime); + return std::make_tuple(Error::None, std::move(source), DataLocation::VectorWithMime); } else { DataSource source = {}; source.path = directory / uri; @@ -586,7 +586,7 @@ fg::Error fg::glTF::parse(Category categories) { void fg::glTF::parseAccessors(simdjson::ondemand::array accessors) { using namespace simdjson; - // parsedAsset->accessors.reserve(accessors.count_elements()); + parsedAsset->accessors.reserve(accessors.count_elements()); for (auto accessorValue : accessors) { // Required fields: "componentType", "count" @@ -649,7 +649,7 @@ void fg::glTF::parseAccessors(simdjson::ondemand::array accessors) { void fg::glTF::parseAnimations(simdjson::ondemand::array animations) { using namespace simdjson; - // parsedAsset->animations.reserve(animations.count_elements()); + parsedAsset->animations.reserve(animations.count_elements()); for (auto animationValue : animations) { ondemand::object animationObject; @@ -664,7 +664,7 @@ void fg::glTF::parseAnimations(simdjson::ondemand::array animations) { RETURN_SET_ERROR(Error::InvalidGltf) } - // animation.channels.reserve(channels.count_elements()); + animation.channels.reserve(channels.count_elements()); for (auto channelValue : channels) { ondemand::object channelObject; AnimationChannel channel = {}; @@ -714,7 +714,7 @@ void fg::glTF::parseAnimations(simdjson::ondemand::array animations) { RETURN_SET_ERROR(Error::InvalidGltf) } - // animation.samplers.reserve(samplers.count_elements()); + animation.samplers.reserve(samplers.count_elements()); for (auto samplerValue : samplers) { ondemand::object samplerObject; AnimationSampler sampler = {}; @@ -766,7 +766,7 @@ void fg::glTF::parseAnimations(simdjson::ondemand::array animations) { void fg::glTF::parseBuffers(simdjson::ondemand::array buffers) { using namespace simdjson; - // parsedAsset->buffers.reserve(buffers.count_elements()); + parsedAsset->buffers.reserve(buffers.count_elements()); size_t bufferIndex = 0; for (auto bufferValue : buffers) { @@ -793,7 +793,7 @@ void fg::glTF::parseBuffers(simdjson::ondemand::array buffers) { RETURN_SET_ERROR(Error::InvalidGltf) } - buffer.data = source; + buffer.data = std::move(source); buffer.location = location; } else if (bufferIndex == 0 && glb != nullptr) { if (hasBit(options, Options::LoadGLBBuffers)) { @@ -829,7 +829,7 @@ void fg::glTF::parseBuffers(simdjson::ondemand::array buffers) { void fg::glTF::parseBufferViews(simdjson::ondemand::array bufferViews) { using namespace simdjson; - // parsedAsset->bufferViews.reserve(bufferViews.count_elements()); + parsedAsset->bufferViews.reserve(bufferViews.count_elements()); for (auto bufferViewValue : bufferViews) { // Required fields: "bufferIndex", "byteLength" @@ -885,7 +885,7 @@ void fg::glTF::parseBufferViews(simdjson::ondemand::array bufferViews) { void fg::glTF::parseCameras(simdjson::ondemand::array cameras) { using namespace simdjson; - // parsedAsset->cameras.reserve(cameras.count_elements()); + parsedAsset->cameras.reserve(cameras.count_elements()); for (auto cameraValue : cameras) { Camera camera = {}; @@ -975,7 +975,7 @@ void fg::glTF::parseCameras(simdjson::ondemand::array cameras) { void fg::glTF::parseImages(simdjson::ondemand::array images) { using namespace simdjson; - // parsedAsset->images.reserve(images.count_elements()); + parsedAsset->images.reserve(images.count_elements()); for (auto imageValue : images) { Image image = {}; @@ -1033,7 +1033,7 @@ void fg::glTF::parseImages(simdjson::ondemand::array images) { void fg::glTF::parseMaterials(simdjson::ondemand::array materials) { using namespace simdjson; - // parsedAsset->materials.reserve(materials.count_elements()); + parsedAsset->materials.reserve(materials.count_elements()); for (auto materialValue : materials) { ondemand::object materialObject; @@ -1180,7 +1180,7 @@ void fg::glTF::parseMaterials(simdjson::ondemand::array materials) { void fg::glTF::parseMeshes(simdjson::ondemand::array meshes) { using namespace simdjson; - // parsedAsset->meshes.reserve(meshes.count_elements()); + parsedAsset->meshes.reserve(meshes.count_elements()); for (auto meshValue : meshes) { // Required fields: "primitives" @@ -1197,7 +1197,7 @@ void fg::glTF::parseMeshes(simdjson::ondemand::array meshes) { } else if (meshError != Error::None) { RETURN_SET_ERROR(meshError) } else { - // mesh.primitives.reserve(primitives.count_elements()); + mesh.primitives.reserve(primitives.count_elements()); for (auto primitiveValue : primitives) { // Required fields: "attributes" Primitive primitive = {}; @@ -1264,7 +1264,7 @@ void fg::glTF::parseMeshes(simdjson::ondemand::array meshes) { void fg::glTF::parseNodes(simdjson::ondemand::array nodes) { using namespace simdjson; - // parsedAsset->nodes.reserve(nodes.count_elements()); + parsedAsset->nodes.reserve(nodes.count_elements()); for (auto nodeValue : nodes) { Node node = {}; @@ -1288,7 +1288,7 @@ void fg::glTF::parseNodes(simdjson::ondemand::array nodes) { ondemand::array children; auto childError = getJsonArray(nodeObject, "children", &children); if (childError == Error::None) { - // node.children.reserve(children.count_elements()); + node.children.reserve(children.count_elements()); for (auto childValue : children) { if (childValue.get_uint64().get(index) != SUCCESS) { RETURN_SET_ERROR(Error::InvalidGltf) @@ -1382,7 +1382,7 @@ void fg::glTF::parseNodes(simdjson::ondemand::array nodes) { void fg::glTF::parseSamplers(simdjson::ondemand::array samplers) { using namespace simdjson; uint64_t number; - // parsedAsset->samplers.reserve(samplers.count_elements()); + parsedAsset->samplers.reserve(samplers.count_elements()); for (auto samplerValue : samplers) { Sampler sampler = {}; @@ -1422,7 +1422,7 @@ void fg::glTF::parseSamplers(simdjson::ondemand::array samplers) { void fg::glTF::parseScenes(simdjson::ondemand::array scenes) { using namespace simdjson; - // parsedAsset->scenes.reserve(scenes.count_elements()); + parsedAsset->scenes.reserve(scenes.count_elements()); for (auto sceneValue : scenes) { // The scene object can be completely empty Scene scene = {}; @@ -1441,7 +1441,7 @@ void fg::glTF::parseScenes(simdjson::ondemand::array scenes) { ondemand::array nodes; auto nodeError = getJsonArray(sceneObject, "nodes", &nodes); if (nodeError == Error::None) { - // scene.nodeIndices.reserve(nodes.count_elements()); + scene.nodeIndices.reserve(nodes.count_elements()); for (auto nodeValue : nodes) { uint64_t index; if (nodeValue.get_uint64().get(index) != SUCCESS) { @@ -1460,7 +1460,7 @@ void fg::glTF::parseScenes(simdjson::ondemand::array scenes) { void fg::glTF::parseSkins(simdjson::ondemand::array skins) { using namespace simdjson; - // parsedAsset->skins.reserve(skins.count_elements()); + parsedAsset->skins.reserve(skins.count_elements()); for (auto skinValue : skins) { Skin skin = {}; @@ -1481,7 +1481,7 @@ void fg::glTF::parseSkins(simdjson::ondemand::array skins) { if (skinObject["joints"].get_array().get(jointsArray) != SUCCESS) { RETURN_SET_ERROR(Error::InvalidGltf) } - // skin.joints.reserve(jointsArray.count_elements()); + skin.joints.reserve(jointsArray.count_elements()); for (auto jointValue : jointsArray) { if (jointValue.get_uint64().get(index) != SUCCESS) { RETURN_SET_ERROR(Error::InvalidGltf) @@ -1580,7 +1580,7 @@ fg::Error fg::glTF::parseTextureObject(void* object, std::string_view key, Textu void fg::glTF::parseTextures(simdjson::ondemand::array textures) { using namespace simdjson; - // parsedAsset->textures.reserve(textures.count_elements()); + parsedAsset->textures.reserve(textures.count_elements()); for (auto textureValue : textures) { Texture texture;