Permission: pass StringView to ParsePermission()

Eliminates a temporary copy.
This commit is contained in:
Max Kellermann 2019-04-03 21:45:01 +02:00
parent 8499a662ea
commit 8f20edac9d

View File

@ -23,6 +23,7 @@
#include "config/Data.hxx" #include "config/Data.hxx"
#include "config/Option.hxx" #include "config/Option.hxx"
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include "util/StringView.hxx"
#include <algorithm> #include <algorithm>
#include <map> #include <map>
@ -54,13 +55,14 @@ static unsigned local_permissions;
#endif #endif
static unsigned static unsigned
ParsePermission(const char *p) ParsePermission(StringView s)
{ {
for (auto i = permission_names; i->name != nullptr; ++i) for (auto i = permission_names; i->name != nullptr; ++i)
if (strcmp(p, i->name) == 0) if (s.Equals(i->name))
return i->value; return i->value;
throw FormatRuntimeError("unknown permission \"%s\"", p); throw FormatRuntimeError("unknown permission \"%.*s\"",
int(s.size), s.data);
} }
static unsigned parsePermissions(const char *string) static unsigned parsePermissions(const char *string)
@ -74,8 +76,7 @@ static unsigned parsePermissions(const char *string)
const char *comma = std::find(string, end, const char *comma = std::find(string, end,
PERMISSION_SEPARATOR); PERMISSION_SEPARATOR);
if (comma > string) { if (comma > string) {
const std::string name(string, comma); permission |= ParsePermission({string, comma});
permission |= ParsePermission(name.c_str());
} }
if (comma == end) if (comma == end)