From 4d59dee5ea25b7f1a7512348de6bc80a09a6d3fa Mon Sep 17 00:00:00 2001 From: Daniel Hritzkiv Date: Fri, 25 Aug 2017 16:52:44 -0400 Subject: [PATCH] Cache retrieved items via an original index map --- code/glTF2Asset.h | 15 ++++++++------- code/glTF2Asset.inl | 11 +++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/code/glTF2Asset.h b/code/glTF2Asset.h index 2ec2b84eb..2b37d6a0e 100644 --- a/code/glTF2Asset.h +++ b/code/glTF2Asset.h @@ -382,6 +382,7 @@ namespace glTF2 struct Object { int index; //!< The index of this object within its property container + int oIndex; //!< The original index of this object defined in the JSON std::string id; //!< The globally unique ID used to reference this object std::string name; //!< The user-defined name of this object @@ -1025,14 +1026,14 @@ namespace glTF2 friend class Asset; friend class AssetWriter; - typedef typename std::gltf_unordered_map< std::string, unsigned int > Dict; + typedef typename std::gltf_unordered_map< unsigned int, unsigned int > Dict; - std::vector mObjs; //! The read objects - Dict mObjsById; //! The read objects accessible by id - const char* mDictId; //! ID of the dictionary object - const char* mExtId; //! ID of the extension defining the dictionary - Value* mDict; //! JSON dictionary object - Asset& mAsset; //! The asset instance + std::vector mObjs; //! The read objects + Dict mObjsByOIndex; //! The read objects accessible by original index + const char* mDictId; //! ID of the dictionary object + const char* mExtId; //! ID of the extension defining the dictionary + Value* mDict; //! JSON dictionary object + Asset& mAsset; //! The asset instance void AttachToDocument(Document& doc); void DetachFromDocument(); diff --git a/code/glTF2Asset.inl b/code/glTF2Asset.inl index 97e507ee6..062d8318d 100644 --- a/code/glTF2Asset.inl +++ b/code/glTF2Asset.inl @@ -204,10 +204,8 @@ template Ref LazyDict::Retrieve(unsigned int i) { - std::string id = std::string(mDictId) + "[" + std::to_string(i) + "]"; - - typename Dict::iterator it = mObjsById.find(id); - if (it != mObjsById.end()) { // already created? + typename Dict::iterator it = mObjsByOIndex.find(i); + if (it != mObjsByOIndex.end()) {// already created? return Ref(mObjs, it->second); } @@ -227,7 +225,8 @@ Ref LazyDict::Retrieve(unsigned int i) } T* inst = new T(); - inst->id = id; + inst->id = std::string(mDictId) + "[" + std::to_string(i) + "]"; + inst->oIndex = i; ReadMember(obj, "name", inst->name); inst->Read(obj, mAsset); @@ -239,7 +238,7 @@ Ref LazyDict::Add(T* obj) { unsigned int idx = unsigned(mObjs.size()); mObjs.push_back(obj); - mObjsById[obj->id] = idx; + mObjsByOIndex[obj->oIndex] = idx; mAsset.mUsedIds[obj->id] = true; return Ref(mObjs, idx); }