Skip to content

Commit

Permalink
src: avoid copying strings in FSPermission::Apply
Browse files Browse the repository at this point in the history
The use of string_view and subsequent copying to a string was supposed
to be a minor optimization in 640a7918, however, since 413c16e, no
string splitting occurs anymore. Therefore, we can simply pass around
some references instead of using string_view or copying strings.

Refs: #48491
Refs: #49047
PR-URL: #50662
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
tniessen authored and UlisesGascon committed Dec 19, 2023
1 parent 6620df1 commit d08eb38
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/permission/fs_permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ namespace permission {
// allow = '/tmp/,/home/example.js'
void FSPermission::Apply(const std::vector<std::string>& allow,
PermissionScope scope) {
using std::string_view_literals::operator""sv;

for (const std::string_view res : allow) {
if (res == "*"sv) {
for (const std::string& res : allow) {
if (res == "*") {
if (scope == PermissionScope::kFileSystemRead) {
deny_all_in_ = false;
allow_all_in_ = true;
Expand All @@ -132,7 +130,7 @@ void FSPermission::Apply(const std::vector<std::string>& allow,
}
return;
}
GrantAccess(scope, std::string(res.data(), res.size()));
GrantAccess(scope, res);
}
}

Expand Down

0 comments on commit d08eb38

Please sign in to comment.