Permission: pass StringView to ParsePermission()
Eliminates a temporary copy.
This commit is contained in:
parent
8499a662ea
commit
8f20edac9d
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user