From e2862abeaf911b6e61ef8335d324efe8b5bc9c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 19 Nov 2023 20:21:35 +0000 Subject: [PATCH] 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 Reviewed-By: Rafael Gonzaga Reviewed-By: Marco Ippolito Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- src/permission/fs_permission.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/permission/fs_permission.cc b/src/permission/fs_permission.cc index 9f8ab281618418..5780d6cb2607e3 100644 --- a/src/permission/fs_permission.cc +++ b/src/permission/fs_permission.cc @@ -119,10 +119,8 @@ namespace permission { // allow = '/tmp/,/home/example.js' void FSPermission::Apply(const std::vector& 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& allow, } return; } - GrantAccess(scope, std::string(res.data(), res.size())); + GrantAccess(scope, res); } }