diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2001-08-28 22:28:31 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2001-08-28 22:28:31 (GMT) |
commit | 5edd7673e1c7182c748584839ab1dec9712150b3 (patch) | |
tree | b781cf2b2427d8e8b9d7da52774597e597487c50 /Source/cmListFileCache.cxx | |
parent | 91f27f6fbc3b1cc2423b09864438f59057e6665f (diff) | |
download | CMake-5edd7673e1c7182c748584839ab1dec9712150b3.zip CMake-5edd7673e1c7182c748584839ab1dec9712150b3.tar.gz CMake-5edd7673e1c7182c748584839ab1dec9712150b3.tar.bz2 |
ENH: add caching for the input CMakeList.txt files, 2X speed up
Diffstat (limited to 'Source/cmListFileCache.cxx')
-rw-r--r-- | Source/cmListFileCache.cxx | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx new file mode 100644 index 0000000..1fade07 --- /dev/null +++ b/Source/cmListFileCache.cxx @@ -0,0 +1,86 @@ +#include "cmListFileCache.h" +#include "cmSystemTools.h" + + +cmListFileCache* cmListFileCache::Instance = 0; + + +cmListFileCache* cmListFileCache::GetInstance() +{ + if(!cmListFileCache::Instance) + { + cmListFileCache::Instance = new cmListFileCache; + } + return cmListFileCache::Instance; +} + + +void cmListFileCache::ClearCache() +{ + delete cmListFileCache::Instance; + cmListFileCache::Instance = 0; +} + + + +cmListFile* cmListFileCache::GetFileCache(const char* path) +{ + ListFileMap::iterator sl = m_ListFileCache.find(path); + if (sl == m_ListFileCache.end()) + { + // if not already in the map, then parse and store the + // file + if(!this->CacheFile(path)) + { + return 0; + } + sl = m_ListFileCache.find(path); + if (sl == m_ListFileCache.end()) + { + cmSystemTools::Error("Fatal error, in cmListFileCache CacheFile failed", + path); + return 0; + } + } + cmListFile& ret = sl->second; + if(cmSystemTools::ModifiedTime(path) > ret.m_ModifiedTime ) + { + if(!this->CacheFile(path)) + { + return 0; + } + else + { + sl = m_ListFileCache.find(path); + return &sl->second; + } + } + return &ret; +} + + +bool cmListFileCache::CacheFile(const char* path) +{ + std::ifstream fin(path); + if(!fin) + { + cmSystemTools::Error("error can not open file ", path); + return false; + } + std::string name; + std::vector<std::string> arguments; + cmListFile inFile; + inFile.m_ModifiedTime = cmSystemTools::ModifiedTime(path); + while ( fin ) + { + cmListFileFunction inFunction; + if(cmSystemTools::ParseFunction(fin, + inFunction.m_Name, + inFunction.m_Arguments)) + { + inFile.m_Functions.push_back(inFunction); + } + } + m_ListFileCache[path] = inFile; + return true; +} |