summaryrefslogtreecommitdiff
path: root/services/incremental/path.cpp
diff options
context:
space:
mode:
authorYurii Zubrytskyi <zyy@google.com>2021-03-23 12:11:11 -0700
committerYurii Zubrytskyi <zyy@google.com>2021-03-23 12:11:11 -0700
commitfe807fd921ecb1c0b4b3364240e3e0b37d2e93c9 (patch)
treeeb46cbce452506c88fd3259d9968ec00f94d5cb1 /services/incremental/path.cpp
parentcb1cc4f5a97217bff3d6dd76597b828cedd269a2 (diff)
[incfs] Optimize path::join for appending
Append path strings to the first argument if it's an rvalue Bug: 183435580 Test: atest libincfs-test service.incremental_test Change-Id: I52c4a1f0e4ad3547aeccac96a3393323e3be9adb
Diffstat (limited to 'services/incremental/path.cpp')
-rw-r--r--services/incremental/path.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/services/incremental/path.cpp b/services/incremental/path.cpp
index 338659d40b46..bf4e9616057c 100644
--- a/services/incremental/path.cpp
+++ b/services/incremental/path.cpp
@@ -44,19 +44,20 @@ bool PathLess::operator()(std::string_view l, std::string_view r) const {
PathCharsLess());
}
-static void preparePathComponent(std::string_view& path, bool trimFront) {
- if (trimFront) {
- while (!path.empty() && path.front() == '/') {
- path.remove_prefix(1);
- }
+static void preparePathComponent(std::string_view& path, bool trimAll) {
+ // need to check for double front slash as a single one has a separate meaning in front
+ while (!path.empty() && path.front() == '/' &&
+ (trimAll || (path.size() > 1 && path[1] == '/'))) {
+ path.remove_prefix(1);
}
- while (!path.empty() && path.back() == '/') {
+ // for the back we don't care about double-vs-single slash difference
+ while (path.size() > !trimAll && path.back() == '/') {
path.remove_suffix(1);
}
}
void details::append_next_path(std::string& target, std::string_view path) {
- preparePathComponent(path, true);
+ preparePathComponent(path, !target.empty());
if (path.empty()) {
return;
}