From 2ee82d593d9e1e5a0d91d43ae9790aec6abc6bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 10 Nov 2023 20:14:33 +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 --- 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 042dc0ff297216..ec8d10e3b371be 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); } }