From dc822da8158af5b568ca01fbb519d7170553376a Mon Sep 17 00:00:00 2001 From: KWSys Robot Date: Fri, 10 Jul 2015 09:36:55 -0400 Subject: KWSys 2015-07-10 (c9336bcf) Extract upstream KWSys using the following shell commands. $ git archive --prefix=upstream-kwsys/ c9336bcf | tar x $ git shortlog --no-merges --abbrev=8 --format='%h %s' d3ba91e1..c9336bcf Brad King (2): 86a24794 SystemTools: Fix GetActualCaseForPath drive letter case handling c9336bcf SystemTools: Optimize GetActualCaseForPath memoization --- SystemTools.cxx | 55 +++++++++++++++++++++++++++++++++++++++--------------- SystemTools.hxx.in | 6 +++++- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/SystemTools.cxx b/SystemTools.cxx index fed1c9c..3452259 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -385,6 +385,26 @@ class SystemToolsTranslationMap : { }; +#ifdef _WIN32 +struct SystemToolsPathCaseCmp +{ + bool operator()(kwsys_stl::string const& l, kwsys_stl::string const& r) const + { +# ifdef _MSC_VER + return _stricmp(l.c_str(), r.c_str()) < 0; +# elif defined(__GNUC__) + return strcasecmp(l.c_str(), r.c_str()) < 0; +# else + return SystemTools::Strucmp(l.c_str(), r.c_str()) < 0; +# endif + } +}; + +class SystemToolsPathCaseMap: + public kwsys_stl::map {}; +#endif + // adds the elements of the env variable path to the arg passed in void SystemTools::GetPath(kwsys_stl::vector& path, const char* env) { @@ -3690,6 +3710,11 @@ static int GetCasePathName(const kwsys_stl::string & pathIn, // Start with root component. kwsys_stl::vector::size_type idx = 0; casePath = path_components[idx++]; + // make sure drive letter is always upper case + if(casePath.size() > 1 && casePath[1] == ':') + { + casePath[0] = toupper(casePath[0]); + } const char* sep = ""; // If network path, fill casePath with server/share so FindFirstFile @@ -3745,27 +3770,21 @@ kwsys_stl::string SystemTools::GetActualCaseForPath(const kwsys_stl::string& p) #ifndef _WIN32 return p; #else - kwsys_stl::string casePath = p; - // make sure drive letter is always upper case - if(casePath.size() > 1 && casePath[1] == ':') - { - casePath[0] = toupper(casePath[0]); - } - // Check to see if actual case has already been called - // for this path, and the result is stored in the LongPathMap - SystemToolsTranslationMap::iterator i = - SystemTools::LongPathMap->find(casePath); - if(i != SystemTools::LongPathMap->end()) + // for this path, and the result is stored in the PathCaseMap + SystemToolsPathCaseMap::iterator i = + SystemTools::PathCaseMap->find(p); + if(i != SystemTools::PathCaseMap->end()) { return i->second; } + kwsys_stl::string casePath; int len = GetCasePathName(p, casePath); if(len == 0 || len > MAX_PATH+1) { return p; } - (*SystemTools::LongPathMap)[p] = casePath; + (*SystemTools::PathCaseMap)[p] = casePath; return casePath; #endif } @@ -5139,7 +5158,9 @@ bool SystemTools::ParseURL( const kwsys_stl::string& URL, // necessary. static unsigned int SystemToolsManagerCount; SystemToolsTranslationMap *SystemTools::TranslationMap; -SystemToolsTranslationMap *SystemTools::LongPathMap; +#ifdef _WIN32 +SystemToolsPathCaseMap *SystemTools::PathCaseMap; +#endif #ifdef __CYGWIN__ SystemToolsTranslationMap *SystemTools::Cyg2Win32Map; #endif @@ -5187,7 +5208,9 @@ void SystemTools::ClassInitialize() #endif // Allocate the translation map first. SystemTools::TranslationMap = new SystemToolsTranslationMap; - SystemTools::LongPathMap = new SystemToolsTranslationMap; +#ifdef _WIN32 + SystemTools::PathCaseMap = new SystemToolsPathCaseMap; +#endif #ifdef __CYGWIN__ SystemTools::Cyg2Win32Map = new SystemToolsTranslationMap; #endif @@ -5244,7 +5267,9 @@ void SystemTools::ClassInitialize() void SystemTools::ClassFinalize() { delete SystemTools::TranslationMap; - delete SystemTools::LongPathMap; +#ifdef _WIN32 + delete SystemTools::PathCaseMap; +#endif #ifdef __CYGWIN__ delete SystemTools::Cyg2Win32Map; #endif diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index 93cde02..7899141 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -54,6 +54,8 @@ namespace @KWSYS_NAMESPACE@ { class SystemToolsTranslationMap; +class SystemToolsPathCaseMap; + /** \class SystemToolsManager * \brief Use to make sure SystemTools is initialized before it is used * and is the last static object destroyed @@ -944,7 +946,9 @@ private: * Each time 'dir' will be found it will be replace by 'refdir' */ static SystemToolsTranslationMap *TranslationMap; - static SystemToolsTranslationMap *LongPathMap; +#ifdef _WIN32 + static SystemToolsPathCaseMap *PathCaseMap; +#endif #ifdef __CYGWIN__ static SystemToolsTranslationMap *Cyg2Win32Map; #endif -- cgit v0.12