summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Niklas Hasse <jhasse@bixense.com>2018-11-13 16:14:06 (GMT)
committerGitHub <noreply@github.com>2018-11-13 16:14:06 (GMT)
commita65f0d42dc8820cc4d80561ddcd4b693c0adc892 (patch)
tree1178162df9a4418536f76d5a5d1ada008180fc49
parentbf7517505ad1def03e13bec2b4131399331bc5c4 (diff)
parent87efe5f206fe138a1e88238153212c5cbac401cd (diff)
downloadNinja-a65f0d42dc8820cc4d80561ddcd4b693c0adc892.zip
Ninja-a65f0d42dc8820cc4d80561ddcd4b693c0adc892.tar.gz
Ninja-a65f0d42dc8820cc4d80561ddcd4b693c0adc892.tar.bz2
Merge pull request #1264 from gahr/DirName-compile-time
DirName's separators and their length are known at compile time
-rw-r--r--src/disk_interface.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc
index 7351715..d4c2fb0 100644
--- a/src/disk_interface.cc
+++ b/src/disk_interface.cc
@@ -35,14 +35,15 @@ namespace {
string DirName(const string& path) {
#ifdef _WIN32
- const char kPathSeparators[] = "\\/";
+ static const char kPathSeparators[] = "\\/";
#else
- const char kPathSeparators[] = "/";
+ static const char kPathSeparators[] = "/";
#endif
+ static const char* const kEnd = kPathSeparators + sizeof(kPathSeparators) - 1;
+
string::size_type slash_pos = path.find_last_of(kPathSeparators);
if (slash_pos == string::npos)
return string(); // Nothing to do.
- const char* const kEnd = kPathSeparators + strlen(kPathSeparators);
while (slash_pos > 0 &&
std::find(kPathSeparators, kEnd, path[slash_pos - 1]) != kEnd)
--slash_pos;