Skip to content

Commit

Permalink
Memory optimization of lookup function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mis1eader-dev committed Oct 9, 2023
1 parent 2caef27 commit 9e2e6f6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/src/HostRedirector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,21 @@ void HostRedirector::lookup(string& host, string& path) const
if (!toHost.empty())
host = toHost;

string newPath = to->path;
if (isWildcard)
{
auto start = path.size() - lastWildcardPathViewLen;
newPath.append(path.substr(
start + (newPath.back() == '/' && path[start] == '/')));
const string& toPath = to->path;
string newPath;
const auto len = path.size();
auto start = len - lastWildcardPathViewLen;
start += toPath.back() == '/' && path[start] == '/';
newPath.reserve(toPath.size() + (len - start));

newPath = toPath;
newPath.append(path.substr(start));
path = std::move(newPath);
}
path = std::move(newPath);
else
path = to->path;
}
else
break;
Expand Down

0 comments on commit 9e2e6f6

Please sign in to comment.