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: nodejs#48491
Refs: nodejs#49047
  • Loading branch information
tniessen committed Nov 17, 2023
1 parent 09c3bb1 commit 2ee82d5
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 2ee82d5

Please sign in to comment.