Skip to content

Commit c3809b9

Browse files
committed
Fix: Preallocate every buffer
1 parent f597952 commit c3809b9

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/fastgltf.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ fg::Error fg::glTF::parse(Category categories) {
646646

647647
void fg::glTF::parseAccessors(simdjson::ondemand::array accessors) {
648648
using namespace simdjson;
649-
// parsedAsset->accessors.reserve(accessors.count_elements());
649+
parsedAsset->accessors.reserve(accessors.count_elements());
650650

651651
for (auto accessorValue : accessors) {
652652
// Required fields: "componentType", "count"
@@ -759,7 +759,7 @@ void fg::glTF::parseAccessors(simdjson::ondemand::array accessors) {
759759

760760
void fg::glTF::parseAnimations(simdjson::ondemand::array animations) {
761761
using namespace simdjson;
762-
// parsedAsset->animations.reserve(animations.count_elements());
762+
parsedAsset->animations.reserve(animations.count_elements());
763763

764764
for (auto animationValue : animations) {
765765
ondemand::object animationObject;
@@ -774,7 +774,7 @@ void fg::glTF::parseAnimations(simdjson::ondemand::array animations) {
774774
SET_ERROR_RETURN(Error::InvalidGltf)
775775
}
776776

777-
// animation.channels.reserve(channels.count_elements());
777+
animation.channels.reserve(channels.count_elements());
778778
for (auto channelValue : channels) {
779779
ondemand::object channelObject;
780780
AnimationChannel channel = {};
@@ -824,7 +824,7 @@ void fg::glTF::parseAnimations(simdjson::ondemand::array animations) {
824824
SET_ERROR_RETURN(Error::InvalidGltf)
825825
}
826826

827-
// animation.samplers.reserve(samplers.count_elements());
827+
animation.samplers.reserve(samplers.count_elements());
828828
for (auto samplerValue : samplers) {
829829
ondemand::object samplerObject;
830830
AnimationSampler sampler = {};
@@ -876,7 +876,7 @@ void fg::glTF::parseAnimations(simdjson::ondemand::array animations) {
876876

877877
void fg::glTF::parseBuffers(simdjson::ondemand::array buffers) {
878878
using namespace simdjson;
879-
// parsedAsset->buffers.reserve(buffers.count_elements());
879+
parsedAsset->buffers.reserve(buffers.count_elements());
880880

881881
size_t bufferIndex = 0;
882882
for (auto bufferValue : buffers) {
@@ -944,7 +944,7 @@ void fg::glTF::parseBuffers(simdjson::ondemand::array buffers) {
944944

945945
void fg::glTF::parseBufferViews(simdjson::ondemand::array bufferViews) {
946946
using namespace simdjson;
947-
// parsedAsset->bufferViews.reserve(bufferViews.count_elements());
947+
parsedAsset->bufferViews.reserve(bufferViews.count_elements());
948948

949949
for (auto bufferViewValue : bufferViews) {
950950
// Required fields: "bufferIndex", "byteLength"
@@ -1049,7 +1049,7 @@ void fg::glTF::parseBufferViews(simdjson::ondemand::array bufferViews) {
10491049

10501050
void fg::glTF::parseCameras(simdjson::ondemand::array cameras) {
10511051
using namespace simdjson;
1052-
// parsedAsset->cameras.reserve(cameras.count_elements());
1052+
parsedAsset->cameras.reserve(cameras.count_elements());
10531053

10541054
for (auto cameraValue : cameras) {
10551055
Camera camera = {};
@@ -1139,7 +1139,7 @@ void fg::glTF::parseCameras(simdjson::ondemand::array cameras) {
11391139

11401140
void fg::glTF::parseImages(simdjson::ondemand::array images) {
11411141
using namespace simdjson;
1142-
// parsedAsset->images.reserve(images.count_elements());
1142+
parsedAsset->images.reserve(images.count_elements());
11431143

11441144
for (auto imageValue : images) {
11451145
Image image = {};
@@ -1197,7 +1197,7 @@ void fg::glTF::parseImages(simdjson::ondemand::array images) {
11971197

11981198
void fg::glTF::parseMaterials(simdjson::ondemand::array materials) {
11991199
using namespace simdjson;
1200-
// parsedAsset->materials.reserve(materials.count_elements());
1200+
parsedAsset->materials.reserve(materials.count_elements());
12011201

12021202
for (auto materialValue : materials) {
12031203
ondemand::object materialObject;
@@ -1334,7 +1334,7 @@ void fg::glTF::parseMaterials(simdjson::ondemand::array materials) {
13341334

13351335
void fg::glTF::parseMeshes(simdjson::ondemand::array meshes) {
13361336
using namespace simdjson;
1337-
// parsedAsset->meshes.reserve(meshes.count_elements());
1337+
parsedAsset->meshes.reserve(meshes.count_elements());
13381338

13391339
for (auto meshValue : meshes) {
13401340
// Required fields: "primitives"
@@ -1351,7 +1351,7 @@ void fg::glTF::parseMeshes(simdjson::ondemand::array meshes) {
13511351
} else if (meshError != Error::None) {
13521352
SET_ERROR_RETURN(meshError)
13531353
} else {
1354-
// mesh.primitives.reserve(array.count_elements());
1354+
mesh.primitives.reserve(array.count_elements());
13551355
for (auto primitiveValue : array) {
13561356
// Required fields: "attributes"
13571357
Primitive primitive = {};
@@ -1441,7 +1441,7 @@ void fg::glTF::parseMeshes(simdjson::ondemand::array meshes) {
14411441

14421442
void fg::glTF::parseNodes(simdjson::ondemand::array nodes) {
14431443
using namespace simdjson;
1444-
// parsedAsset->nodes.reserve(nodes.count_elements());
1444+
parsedAsset->nodes.reserve(nodes.count_elements());
14451445

14461446
for (auto nodeValue : nodes) {
14471447
Node node = {};
@@ -1570,7 +1570,7 @@ void fg::glTF::parseNodes(simdjson::ondemand::array nodes) {
15701570
void fg::glTF::parseSamplers(simdjson::ondemand::array samplers) {
15711571
using namespace simdjson;
15721572
uint64_t number;
1573-
// parsedAsset->samplers.reserve(samplers.count_elements());
1573+
parsedAsset->samplers.reserve(samplers.count_elements());
15741574

15751575
for (auto samplerValue : samplers) {
15761576
Sampler sampler = {};
@@ -1609,7 +1609,7 @@ void fg::glTF::parseSamplers(simdjson::ondemand::array samplers) {
16091609

16101610
void fg::glTF::parseScenes(simdjson::ondemand::array scenes) {
16111611
using namespace simdjson;
1612-
// parsedAsset->scenes.reserve(scenes.count_elements());
1612+
parsedAsset->scenes.reserve(scenes.count_elements());
16131613
for (auto sceneValue : scenes) {
16141614
// The scene object can be completely empty
16151615
Scene scene = {};
@@ -1628,7 +1628,7 @@ void fg::glTF::parseScenes(simdjson::ondemand::array scenes) {
16281628
ondemand::array nodes;
16291629
auto nodeError = getJsonArray(sceneObject, "nodes", &nodes);
16301630
if (nodeError == Error::None) {
1631-
// scene.nodeIndices.reserve(nodes.count_elements());
1631+
scene.nodeIndices.reserve(nodes.count_elements());
16321632
for (auto nodeValue : nodes) {
16331633
uint64_t index;
16341634
if (nodeValue.get_uint64().get(index) != SUCCESS) {
@@ -1647,7 +1647,7 @@ void fg::glTF::parseScenes(simdjson::ondemand::array scenes) {
16471647

16481648
void fg::glTF::parseSkins(simdjson::ondemand::array skins) {
16491649
using namespace simdjson;
1650-
// parsedAsset->skins.reserve(skins.count_elements());
1650+
parsedAsset->skins.reserve(skins.count_elements());
16511651

16521652
for (auto skinValue : skins) {
16531653
Skin skin = {};
@@ -1668,7 +1668,7 @@ void fg::glTF::parseSkins(simdjson::ondemand::array skins) {
16681668
if (skinObject["joints"].get_array().get(jointsArray) != SUCCESS) {
16691669
SET_ERROR_RETURN(Error::InvalidGltf)
16701670
}
1671-
// skin.joints.reserve(jointsArray.count_elements());
1671+
skin.joints.reserve(jointsArray.count_elements());
16721672
for (auto jointValue : jointsArray) {
16731673
if (jointValue.get_uint64().get(index) != SUCCESS) {
16741674
SET_ERROR_RETURN(Error::InvalidGltf)
@@ -1767,7 +1767,7 @@ fg::Error fg::glTF::parseTextureObject(void* object, std::string_view key, Textu
17671767

17681768
void fg::glTF::parseTextures(simdjson::ondemand::array textures) {
17691769
using namespace simdjson;
1770-
// parsedAsset->textures.reserve(textures.count_elements());
1770+
parsedAsset->textures.reserve(textures.count_elements());
17711771

17721772
for (auto textureValue : textures) {
17731773
Texture texture;

0 commit comments

Comments
 (0)