src_avoid_copying_string_in_fs_permission.patch 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Keeley Hammond <[email protected]>
  3. Date: Mon, 6 Nov 2023 14:37:50 -0800
  4. Subject: src: avoid copying string in fs_permission
  5. Ref: https://github.com/nodejs/node/pull/47746/files
  6. diff --git a/src/permission/fs_permission.cc b/src/permission/fs_permission.cc
  7. index fadf75968c779d5aee8d9d1ee27e7b4abf241240..d407d440d74c66d9dc8ca4d4653096292c5adc4c 100644
  8. --- a/src/permission/fs_permission.cc
  9. +++ b/src/permission/fs_permission.cc
  10. @@ -199,18 +199,18 @@ bool FSPermission::RadixTree::Lookup(const std::string_view& s,
  11. }
  12. }
  13. -void FSPermission::RadixTree::Insert(const std::string& path) {
  14. +void FSPermission::RadixTree::Insert(const std::string& path_prefix) {
  15. FSPermission::RadixTree::Node* current_node = root_node_;
  16. unsigned int parent_node_prefix_len = current_node->prefix.length();
  17. - int path_len = path.length();
  18. + int path_len = path_prefix.length();
  19. for (int i = 1; i <= path_len; ++i) {
  20. - bool is_wildcard_node = path[i - 1] == '*';
  21. + bool is_wildcard_node = path_prefix[i - 1] == '*';
  22. bool is_last_char = i == path_len;
  23. if (is_wildcard_node || is_last_char) {
  24. - std::string node_path = path.substr(parent_node_prefix_len, i);
  25. + std::string node_path = path_prefix.substr(parent_node_prefix_len, i);
  26. current_node = current_node->CreateChild(node_path);
  27. }
  28. @@ -222,7 +222,7 @@ void FSPermission::RadixTree::Insert(const std::string& path) {
  29. if (UNLIKELY(per_process::enabled_debug_list.enabled(
  30. DebugCategory::PERMISSION_MODEL))) {
  31. - per_process::Debug(DebugCategory::PERMISSION_MODEL, "Inserting %s\n", path);
  32. + per_process::Debug(DebugCategory::PERMISSION_MODEL, "Inserting %s\n", path_prefix);
  33. PrintTree(root_node_);
  34. }
  35. }
  36. diff --git a/src/permission/fs_permission.h b/src/permission/fs_permission.h
  37. index 244e95727ad48757995c6404f457f42a4ba33ccd..4b6aab197333928bfbd5143bea15b3a5abd6d4c0 100644
  38. --- a/src/permission/fs_permission.h
  39. +++ b/src/permission/fs_permission.h
  40. @@ -31,16 +31,16 @@ class FSPermission final : public PermissionBase {
  41. Node() : wildcard_child(nullptr), is_leaf(false) {}
  42. - Node* CreateChild(std::string prefix) {
  43. - if (prefix.empty() && !is_leaf) {
  44. + Node* CreateChild(std::string path_prefix) {
  45. + if (path_prefix.empty() && !is_leaf) {
  46. is_leaf = true;
  47. return this;
  48. }
  49. - char label = prefix[0];
  50. + char label = path_prefix[0];
  51. Node* child = children[label];
  52. if (child == nullptr) {
  53. - children[label] = new Node(prefix);
  54. + children[label] = new Node(path_prefix);
  55. return children[label];
  56. }
  57. @@ -48,7 +48,7 @@ class FSPermission final : public PermissionBase {
  58. unsigned int i = 0;
  59. unsigned int prefix_len = prefix.length();
  60. for (; i < child->prefix.length(); ++i) {
  61. - if (i > prefix_len || prefix[i] != child->prefix[i]) {
  62. + if (i > prefix_len || path_prefix[i] != child->prefix[i]) {
  63. std::string parent_prefix = child->prefix.substr(0, i);
  64. std::string child_prefix = child->prefix.substr(i);
  65. @@ -57,11 +57,11 @@ class FSPermission final : public PermissionBase {
  66. split_child->children[child_prefix[0]] = child;
  67. children[parent_prefix[0]] = split_child;
  68. - return split_child->CreateChild(prefix.substr(i));
  69. + return split_child->CreateChild(path_prefix.substr(i));
  70. }
  71. }
  72. child->is_leaf = true;
  73. - return child->CreateChild(prefix.substr(i));
  74. + return child->CreateChild(path_prefix.substr(i));
  75. }
  76. Node* CreateWildcardChild() {