src: avoid copying strings in FSPermission::Apply

The use of string_view and subsequent copying to a string was supposed
to be a minor optimization in 640a7918, however, since 413c16e4, no
string splitting occurs anymore. Therefore, we can simply pass around
some references instead of using string_view or copying strings.

Refs: https://github.com/nodejs/node/pull/48491
Refs: https://github.com/nodejs/node/pull/49047
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Tobias Nießen 2023-11-19 20:21:35 +00:00 committed by GitHub
parent 2059913f31
commit 48f32d71a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
@ -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);
}
}