remove Common::TrimSourcePath

wwylele / 白疾風Today at 6:14 PM
I doubt the performance of constructing regex everytime the function is called
Is TrimSourcePath only called by logging? if so, you can move the implementation into logging, and cache the regex object into global
This function is probably too specific to be in common anyway
This commit is contained in:
BreadFish64 2019-03-10 19:18:09 -05:00
parent 605dfe80e7
commit 36e368ff99
3 changed files with 4 additions and 28 deletions

View file

@ -7,7 +7,6 @@
#include <codecvt>
#include <cstdlib>
#include <locale>
#include <regex>
#include <sstream>
#include "common/common_paths.h"
#include "common/logging/log.h"
@ -210,18 +209,4 @@ std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t
return std::string(buffer, len);
}
std::string TrimSourcePath(const std::string& file_path, const std::vector<std::string>& roots) {
// match from beginning of path to dir sep
std::string regex_src = R"(.*([\/\\]|^)()";
// plus the last occurrence of any root
for (auto root = roots.begin(); root < roots.end() - 1; ++root) {
regex_src += '(' + *root + ")|";
}
regex_src += '(' + roots.back() + ')';
// plus dir sep
regex_src += R"()[\/\\])";
std::regex regex(regex_src);
return std::regex_replace(file_path, regex, "");
}
} // namespace Common