Cache retrieved items via an original index map

pull/1423/head
Daniel Hritzkiv 2017-08-25 16:52:44 -04:00
parent 47c7c3cf50
commit 4d59dee5ea
No known key found for this signature in database
GPG Key ID: D1D19875679D5CBF
2 changed files with 13 additions and 13 deletions

View File

@ -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<T*> 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<T*> 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();

View File

@ -204,10 +204,8 @@ template<class T>
Ref<T> LazyDict<T>::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<T>(mObjs, it->second);
}
@ -227,7 +225,8 @@ Ref<T> LazyDict<T>::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<T> LazyDict<T>::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<T>(mObjs, idx);
}