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 <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
tniessen authored and targos committed Nov 23, 2023
1 parent 6f427b5 commit e2862ab
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 e2862ab

Please sign in to comment.