From: Markus R. <rol...@us...> - 2007-02-18 12:02:08
|
Update of /cvsroot/simspark/simspark/spark/zeitgeist In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv21546/zeitgeist Modified Files: Tag: WIN32 core.cpp core.h Log Message: - use a map instead of a list of registered bundles - check if a bundle was previously registered and don't load it twice Index: core.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/core.cpp,v retrieving revision 1.2.2.3 retrieving revision 1.2.2.4 diff -C2 -d -r1.2.2.3 -r1.2.2.4 *** core.cpp 16 Feb 2007 15:36:51 -0000 1.2.2.3 --- core.cpp 18 Feb 2007 12:01:55 -0000 1.2.2.4 *************** *** 276,281 **** bool Core::ImportBundle(const std::string& bundleName) { ! shared_ptr<SharedLibrary> bundle(new SharedLibrary()); if (!bundle->Open(bundleName)) { --- 276,287 ---- bool Core::ImportBundle(const std::string& bundleName) { ! TBundleMap::const_iterator iter = mBundles.find(bundleName); ! if (iter != mBundles.end()) ! { ! // already imported ! return true; ! } + shared_ptr<SharedLibrary> bundle(new SharedLibrary()); if (!bundle->Open(bundleName)) { *************** *** 302,306 **** while(!classes.empty()) { - //shared_ptr<Class> theClass(classes.back()); if (RegisterClassObject(classes.back(), "")) { --- 308,311 ---- *************** *** 312,318 **** } ! // we only add the bundle, if it contained a class which was registered if (usingClass) ! mBundles.push_back(bundle); return true; --- 317,324 ---- } ! // we only add the bundle, if it contained a class which was ! // registered if (usingClass) ! mBundles[bundleName] = bundle; return true; *************** *** 344,348 **** { return entry; ! } // remove entry as it points to an expired node --- 350,354 ---- { return entry; ! } // remove entry as it points to an expired node *************** *** 479,494 **** } - template <class T> - struct isUnique: public unary_function<T, bool> - { - bool operator()(const T& x){ return x.unique(); } - }; - void Core::GarbageCollectBundles() { ! // don't you just love the STL ;-) ! mBundles.erase(remove_if( ! mBundles.begin(), mBundles.end(), ! isUnique<shared_ptr<SharedLibrary> >() ! ), mBundles.end()); } --- 485,503 ---- } void Core::GarbageCollectBundles() { ! TBundleMap::iterator iter = mBundles.begin(); ! ! while (iter != mBundles.end()) ! { ! const TBundlePair& entry = (*iter); ! if (entry.second.unique()) ! { ! mBundles.erase(iter); ! iter = mBundles.begin(); ! continue; ! } ! ! ++iter; ! } } Index: core.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/core.h,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -C2 -d -r1.2.2.2 -r1.2.2.3 *** core.h 18 Feb 2007 08:51:04 -0000 1.2.2.2 --- core.h 18 Feb 2007 12:01:56 -0000 1.2.2.3 *************** *** 189,192 **** --- 189,196 ---- typedef std::map<CacheKey, boost::weak_ptr<Leaf> > TPathCache; + /** TBundleMap defines a registry of loaded bundles */ + typedef std::pair<std::string, boost::shared_ptr<salt::SharedLibrary> > TBundlePair; + typedef std::map<std::string, boost::shared_ptr<salt::SharedLibrary> > TBundleMap; + // // functions *************** *** 339,347 **** boost::weak_ptr<Core> mSelf; ! /** a list of all registered bundles. Whenever we load a ! bundle, we add it to this list. This is necessary, because ! we have to keep the connection to each bundle open, until ! all the class objects belonging to it are completely ! destructed. This workaround is very ugly ... it cost me about 3-4 --- 343,350 ---- boost::weak_ptr<Core> mSelf; ! /** a registry of all registered bundles. Whenever we load a ! bundle, we add it to this map. This is necessary, because we ! have to keep the connection to each bundle open, until all the ! class objects belonging to it are completely destructed. This workaround is very ugly ... it cost me about 3-4 *************** *** 365,369 **** enough. */ ! std::list<boost::shared_ptr<salt::SharedLibrary> > mBundles; //! the internal node lookup cache --- 368,372 ---- enough. */ ! TBundleMap mBundles; //! the internal node lookup cache |