Skip to content

Commit

Permalink
Fix: Preallocate every buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Oct 17, 2022
1 parent 0a78e2a commit 6409d34
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/fastgltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ std::tuple<fg::Error, fg::DataSource, fg::DataLocation> 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;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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 = {};
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand All @@ -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 = {};
Expand Down Expand Up @@ -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 = {};
Expand All @@ -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)
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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 = {};
Expand All @@ -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) {
Expand All @@ -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 = {};
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6409d34

Please sign in to comment.