mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-11 17:49:38 -06:00
KWSys 2024-11-06 (81583094)
Code extracted from:
https://gitlab.kitware.com/utils/kwsys.git
at commit 81583094b092d08e153e4966224639c7b257d25c (master).
Upstream Shortlog
-----------------
Brad King (1):
30e9db2d SystemTools: Drop GetActualCaseForPathCached
This commit is contained in:
committed by
Brad King
parent
10a381e446
commit
9b1a873de8
111
SystemTools.cxx
111
SystemTools.cxx
@@ -490,45 +490,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
# if defined(_WIN64)
|
||||
static constexpr size_t FNV_OFFSET_BASIS = 14695981039346656037ULL;
|
||||
static constexpr size_t FNV_PRIME = 1099511628211ULL;
|
||||
# else
|
||||
static constexpr size_t FNV_OFFSET_BASIS = 2166136261U;
|
||||
static constexpr size_t FNV_PRIME = 16777619U;
|
||||
# endif
|
||||
|
||||
// Case insensitive Fnv1a hash
|
||||
struct SystemToolsPathCaseHash
|
||||
{
|
||||
size_t operator()(std::string const& path) const
|
||||
{
|
||||
size_t hash = FNV_OFFSET_BASIS;
|
||||
for (auto c : path) {
|
||||
hash ^= static_cast<size_t>(std::tolower(c));
|
||||
hash *= FNV_PRIME;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
struct SystemToolsPathCaseEqual
|
||||
{
|
||||
bool operator()(std::string const& l, std::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
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* SystemTools static variables singleton class.
|
||||
*/
|
||||
@@ -536,16 +497,8 @@ class SystemToolsStatic
|
||||
{
|
||||
public:
|
||||
#ifdef _WIN32
|
||||
static std::string GetCasePathName(std::string const& pathIn,
|
||||
bool const cache);
|
||||
static std::string GetActualCaseForPathCached(std::string const& path);
|
||||
static std::string GetCasePathName(std::string const& pathIn);
|
||||
static const char* GetEnvBuffered(const char* key);
|
||||
std::unordered_map<std::string, std::string, SystemToolsPathCaseHash,
|
||||
SystemToolsPathCaseEqual>
|
||||
FindFileMap;
|
||||
std::unordered_map<std::string, std::string, SystemToolsPathCaseHash,
|
||||
SystemToolsPathCaseEqual>
|
||||
PathCaseMap;
|
||||
std::map<std::string, std::string> EnvMap;
|
||||
#endif
|
||||
|
||||
@@ -574,8 +527,7 @@ public:
|
||||
static SystemToolsStatic* SystemToolsStatics;
|
||||
|
||||
#ifdef _WIN32
|
||||
std::string SystemToolsStatic::GetCasePathName(std::string const& pathIn,
|
||||
bool const cache)
|
||||
std::string SystemToolsStatic::GetCasePathName(std::string const& pathIn)
|
||||
{
|
||||
std::string casePath;
|
||||
|
||||
@@ -628,30 +580,15 @@ std::string SystemToolsStatic::GetCasePathName(std::string const& pathIn,
|
||||
std::string test_str = casePath;
|
||||
test_str += path_components[idx];
|
||||
|
||||
bool found_in_cache = false;
|
||||
if (cache) {
|
||||
auto const it = SystemToolsStatics->FindFileMap.find(test_str);
|
||||
if (it != SystemToolsStatics->FindFileMap.end()) {
|
||||
path_components[idx] = it->second;
|
||||
found_in_cache = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found_in_cache) {
|
||||
WIN32_FIND_DATAW findData;
|
||||
HANDLE hFind =
|
||||
::FindFirstFileW(Encoding::ToWide(test_str).c_str(), &findData);
|
||||
if (INVALID_HANDLE_VALUE != hFind) {
|
||||
auto case_file_name = Encoding::ToNarrow(findData.cFileName);
|
||||
if (cache) {
|
||||
SystemToolsStatics->FindFileMap.emplace(test_str,
|
||||
case_file_name);
|
||||
}
|
||||
path_components[idx] = std::move(case_file_name);
|
||||
::FindClose(hFind);
|
||||
} else {
|
||||
converting = false;
|
||||
}
|
||||
WIN32_FIND_DATAW findData;
|
||||
HANDLE hFind =
|
||||
::FindFirstFileW(Encoding::ToWide(test_str).c_str(), &findData);
|
||||
if (INVALID_HANDLE_VALUE != hFind) {
|
||||
auto case_file_name = Encoding::ToNarrow(findData.cFileName);
|
||||
path_components[idx] = std::move(case_file_name);
|
||||
::FindClose(hFind);
|
||||
} else {
|
||||
converting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -660,21 +597,6 @@ std::string SystemToolsStatic::GetCasePathName(std::string const& pathIn,
|
||||
}
|
||||
return casePath;
|
||||
}
|
||||
|
||||
std::string SystemToolsStatic::GetActualCaseForPathCached(std::string const& p)
|
||||
{
|
||||
std::string casePath;
|
||||
|
||||
auto it = SystemToolsStatics->PathCaseMap.find(p);
|
||||
if (it != SystemToolsStatics->PathCaseMap.end()) {
|
||||
casePath = it->second;
|
||||
} else {
|
||||
casePath = SystemToolsStatic::GetCasePathName(p, true);
|
||||
SystemToolsStatics->PathCaseMap.emplace(p, casePath);
|
||||
}
|
||||
|
||||
return casePath;
|
||||
}
|
||||
#endif
|
||||
|
||||
// adds the elements of the env variable path to the arg passed in
|
||||
@@ -3654,16 +3576,7 @@ std::string SystemTools::RelativePath(const std::string& local,
|
||||
std::string SystemTools::GetActualCaseForPath(const std::string& p)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return SystemToolsStatic::GetCasePathName(p, false);
|
||||
#else
|
||||
return p;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string SystemTools::GetActualCaseForPathCached(const std::string& p)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return SystemToolsStatic::GetActualCaseForPathCached(p);
|
||||
return SystemToolsStatic::GetCasePathName(p);
|
||||
#else
|
||||
return p;
|
||||
#endif
|
||||
|
||||
@@ -372,7 +372,6 @@ public:
|
||||
* This does nothing on non-Windows systems but return the path.
|
||||
*/
|
||||
static std::string GetActualCaseForPath(const std::string& path);
|
||||
static std::string GetActualCaseForPathCached(const std::string& path);
|
||||
|
||||
/**
|
||||
* Given the path to a program executable, get the directory part of
|
||||
|
||||
Reference in New Issue
Block a user