Skip to content
Snippets Groups Projects
Commit b2ba8780 authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Optimize directory path building with string_view

parent fdc9c2e7
No related branches found
No related tags found
No related merge requests found
......@@ -1108,20 +1108,20 @@ void LLDir::dumpCurrentDirectories(LLError::ELevel level)
LL_VLOGS(level, "AppInit", "Directories") << " UserSkinDir: " << getUserSkinDir() << LL_ENDL;
}
void LLDir::append(std::string& destpath, const std::string& name) const
void LLDir::append(std::string& destpath, std::string_view name) const
{
// Delegate question of whether we need a separator to helper method.
SepOff sepoff(needSep(destpath, name));
if (sepoff.first) // do we need a separator?
{
destpath += mDirDelimiter;
destpath.append(mDirDelimiter);
}
// If destpath ends with a separator, AND name starts with one, skip
// name's leading separator.
destpath += name.substr(sepoff.second);
destpath.append(name.substr(sepoff.second));
}
LLDir::SepOff LLDir::needSep(const std::string& path, const std::string& name) const
LLDir::SepOff LLDir::needSep(std::string_view path, std::string_view name) const
{
if (path.empty() || name.empty())
{
......
......@@ -201,11 +201,11 @@ class LLDir
/// Append specified @a name to @a destpath, separated by getDirDelimiter()
/// if both are non-empty.
void append(std::string& destpath, const std::string& name) const;
void append(std::string& destpath, std::string_view name) const;
/// Variadic form: append @a name0 and @a name1 and arbitrary other @a
/// names to @a destpath, separated by getDirDelimiter() as needed.
template <typename... NAMES>
void append(std::string& destpath, const std::string& name0, const std::string& name1,
void append(std::string& destpath, std::string_view name0, std::string_view name1,
const NAMES& ... names) const
{
// In a typical recursion case, we'd accept (destpath, name0, names).
......@@ -230,7 +230,7 @@ class LLDir
protected:
// Does an add() or append() call need a directory delimiter?
typedef std::pair<bool, unsigned short> SepOff;
SepOff needSep(const std::string& path, const std::string& name) const;
SepOff needSep(std::string_view path, std::string_view name) const;
// build mSearchSkinDirs without adding duplicates
void addSearchSkinDir(const std::string& skindir);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment