summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-07-15 14:48:18 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2014-07-15 14:48:18 (GMT)
commitc005d9566226f15368af7d772734265fe8916289 (patch)
treeef6bd3d9f52e28259818dcd3c1e9ee0267289d74 /Source
parent29abb3dedb7eca410083ee1e5424fddd24b1d4d6 (diff)
parent43a8c5526d12c1346793ced5a4be85b9e9a3d695 (diff)
downloadCMake-c005d9566226f15368af7d772734265fe8916289.zip
CMake-c005d9566226f15368af7d772734265fe8916289.tar.gz
CMake-c005d9566226f15368af7d772734265fe8916289.tar.bz2
Merge topic 'dev/ison-isoff-performance'
43a8c552 SystemTools: Use a set in Is{On,Off} 9270aa9a IsOff: Use the length for the string construction
Diffstat (limited to 'Source')
-rw-r--r--Source/cmSystemTools.cxx42
1 files changed, 36 insertions, 6 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 12a63b0..444e143 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -384,14 +384,28 @@ bool cmSystemTools::IsOn(const char* val)
{
return false;
}
- std::basic_string<char> v = val;
+ size_t len = strlen(val);
+ if (len > 4)
+ {
+ return false;
+ }
+ std::basic_string<char> v(val, len);
+ static std::set<std::string> onValues;
+ if(onValues.empty())
+ {
+ onValues.insert("ON");
+ onValues.insert("1");
+ onValues.insert("YES");
+ onValues.insert("TRUE");
+ onValues.insert("Y");
+ }
for(std::basic_string<char>::iterator c = v.begin();
c != v.end(); c++)
{
*c = static_cast<char>(toupper(*c));
}
- return (v == "ON" || v == "1" || v == "YES" || v == "TRUE" || v == "Y");
+ return (onValues.count(v) > 0);
}
bool cmSystemTools::IsNOTFOUND(const char* val)
@@ -406,19 +420,35 @@ bool cmSystemTools::IsNOTFOUND(const char* val)
bool cmSystemTools::IsOff(const char* val)
{
- if (!val || strlen(val) == 0)
+ if (!val || !*val)
{
return true;
}
- std::basic_string<char> v = val;
+ size_t len = strlen(val);
+ // Try and avoid toupper() for large strings.
+ if (len > 6)
+ {
+ return cmSystemTools::IsNOTFOUND(val);
+ }
+ static std::set<std::string> offValues;
+ if(offValues.empty())
+ {
+ offValues.insert("OFF");
+ offValues.insert("0");
+ offValues.insert("NO");
+ offValues.insert("FALSE");
+ offValues.insert("N");
+ offValues.insert("IGNORE");
+ }
+ // Try and avoid toupper().
+ std::basic_string<char> v(val, len);
for(std::basic_string<char>::iterator c = v.begin();
c != v.end(); c++)
{
*c = static_cast<char>(toupper(*c));
}
- return (v == "OFF" || v == "0" || v == "NO" || v == "FALSE" ||
- v == "N" || cmSystemTools::IsNOTFOUND(v.c_str()) || v == "IGNORE");
+ return (offValues.count(v) > 0);
}
//----------------------------------------------------------------------------