diff options
author | Ruslan Manaev <manavrion@gmail.com> | 2020-10-07 18:39:50 (GMT) |
---|---|---|
committer | Ruslan Manaev <manavrion@gmail.com> | 2020-10-07 18:39:50 (GMT) |
commit | 113ca75c30b010eb4c5df1a8e3794966a2e1437a (patch) | |
tree | 36b37fc7ca73719bd62c089d71817a0d89e16531 /googletest | |
parent | 1fb1bb23bb8418dc73a5a9a82bbed31dc610fec7 (diff) | |
download | googletest-113ca75c30b010eb4c5df1a8e3794966a2e1437a.zip googletest-113ca75c30b010eb4c5df1a8e3794966a2e1437a.tar.gz googletest-113ca75c30b010eb4c5df1a8e3794966a2e1437a.tar.bz2 |
Improve FilePath::Normalize methodrefs/pull/3044/head
Diffstat (limited to 'googletest')
-rw-r--r-- | googletest/src/gtest-filepath.cc | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index 062b95b..af29768 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -349,21 +349,19 @@ FilePath FilePath::RemoveTrailingPathSeparator() const { // For example, "bar///foo" becomes "bar/foo". Does not eliminate other // redundancies that might be in a pathname involving "." or "..". void FilePath::Normalize() { - std::string normalized_pathname; - normalized_pathname.reserve(pathname_.length()); + auto out = pathname_.begin(); for (const char character : pathname_) { if (!IsPathSeparator(character)) { - normalized_pathname.push_back(character); - } else if (normalized_pathname.empty() || - normalized_pathname.back() != kPathSeparator) { - normalized_pathname.push_back(kPathSeparator); + *(out++) = character; + } else if (out == pathname_.begin() || *std::prev(out) != kPathSeparator) { + *(out++) = kPathSeparator; } else { continue; } } - pathname_ = normalized_pathname; + pathname_.erase(out, pathname_.end()); } } // namespace internal |