Commit cdddaf21 authored by Max Kellermann's avatar Max Kellermann

db/simple/Directory: optimize GetName() using the parent's path

This method gets called a lot during MPD startup, via FindChild() and directory_load_subdir(), so this is worth optimizing at the expense of code readability. This speeds up MPD startup by 10%.
parent b267ba5f
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
#include "util/Alloc.hxx" #include "util/Alloc.hxx"
#include "util/DeleteDisposer.hxx" #include "util/DeleteDisposer.hxx"
#include "util/StringCompare.hxx"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
...@@ -69,7 +70,15 @@ Directory::GetName() const noexcept ...@@ -69,7 +70,15 @@ Directory::GetName() const noexcept
{ {
assert(!IsRoot()); assert(!IsRoot());
return PathTraitsUTF8::GetBase(path.c_str()); if (parent->IsRoot())
return path.c_str();
assert(StringAfterPrefix(path.c_str(), parent->path.c_str()) != nullptr);
assert(*StringAfterPrefix(path.c_str(), parent->path.c_str()) == PathTraitsUTF8::SEPARATOR);
/* strip the parent directory path and the slash separator
from this directory's path, and the base name remains */
return path.c_str() + parent->path.length() + 1;
} }
Directory * Directory *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment