From 048c8d953c2b75267376b7b0154b3541b0772422 Mon Sep 17 00:00:00 2001 From: songruining Date: Fri, 23 Aug 2024 17:38:08 +0800 Subject: [PATCH 1/2] perf: reserve memory for prim children --- src/usdc-reader.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usdc-reader.cc b/src/usdc-reader.cc index a967aa07..cb042d19 100644 --- a/src/usdc-reader.cc +++ b/src/usdc-reader.cc @@ -3293,6 +3293,7 @@ bool USDCReader::Impl::ReconstructPrimRecursively( { const crate::CrateReader::Node &node = _nodes[size_t(current)]; DCOUT("node.Children.size = " << node.GetChildren().size()); + currPrimPtr->children().reserve(node.GetChildren().size()); for (size_t i = 0; i < node.GetChildren().size(); i++) { DCOUT("Reconstuct Prim children: " << i << " / " << node.GetChildren().size()); From af94a6dd967e9b84ea401826b4d1f58ccb4d3a64 Mon Sep 17 00:00:00 2001 From: songruining Date: Fri, 23 Aug 2024 18:57:15 +0800 Subject: [PATCH 2/2] fix: add protection for nullptr --- src/usdc-reader.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/usdc-reader.cc b/src/usdc-reader.cc index cb042d19..c0de77e1 100644 --- a/src/usdc-reader.cc +++ b/src/usdc-reader.cc @@ -3293,7 +3293,9 @@ bool USDCReader::Impl::ReconstructPrimRecursively( { const crate::CrateReader::Node &node = _nodes[size_t(current)]; DCOUT("node.Children.size = " << node.GetChildren().size()); - currPrimPtr->children().reserve(node.GetChildren().size()); + if (currPrimPtr) { + currPrimPtr->children().reserve(node.GetChildren().size()); + } for (size_t i = 0; i < node.GetChildren().size(); i++) { DCOUT("Reconstuct Prim children: " << i << " / " << node.GetChildren().size());