| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,10 +11,11 @@ | |||
| 11 | 11 | #endif | |
| 12 | 12 | ||
| 13 | 13 | #include <errno.h> | |
| 14 | - #include <sstream> | ||
| 15 | - #include <limits> | ||
| 16 | 14 | #include <algorithm> | |
| 17 | 15 | #include <cstdlib> // strtoul, errno | |
| 16 | + #include <limits> | ||
| 17 | + #include <sstream> | ||
| 18 | + #include <string_view> | ||
| 18 | 19 | ||
| 19 | 20 | using v8::Boolean; | |
| 20 | 21 | using v8::Context; | |
@@ -50,14 +51,15 @@ void DebugOptions::CheckOptions(std::vector<std::string>* errors, | |||
| 50 | 51 | "`node --inspect-brk` instead."); | |
| 51 | 52 | } | |
| 52 | 53 | ||
| 53 | - std::vector<std::string> destinations = | ||
| 54 | - SplitString(inspect_publish_uid_string, ','); | ||
| 54 | + using std::string_view_literals::operator""sv; | ||
| 55 | + const std::vector<std::string_view> destinations = | ||
| 56 | + SplitString(inspect_publish_uid_string, ","sv); | ||
| 55 | 57 | inspect_publish_uid.console = false; | |
| 56 | 58 | inspect_publish_uid.http = false; | |
| 57 | - for (const std::string& destination : destinations) { | ||
| 58 | - if (destination == "stderr") { | ||
| 59 | + for (const std::string_view destination : destinations) { | ||
| 60 | + if (destination == "stderr"sv) { | ||
| 59 | 61 | inspect_publish_uid.console = true; | |
| 60 | - } else if (destination == "http") { | ||
| 62 | + } else if (destination == "http"sv) { | ||
| 61 | 63 | inspect_publish_uid.http = true; | |
| 62 | 64 | } else { | |
| 63 | 65 | errors->push_back("--inspect-publish-uid destination can be " | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| 5 | 5 | ||
| 6 | 6 | #include <memory> | |
| 7 | + #include <string_view> | ||
| 7 | 8 | ||
| 8 | 9 | #include "env-inl.h" | |
| 9 | 10 | #include "node.h" | |
@@ -126,15 +127,23 @@ struct V8Platform { | |||
| 126 | 127 | } | |
| 127 | 128 | ||
| 128 | 129 | inline void StartTracingAgent() { | |
| 130 | + constexpr auto convert_to_set = | ||
| 131 | + [](std::vector<std::string_view> categories) -> std::set<std::string> { | ||
| 132 | + std::set<std::string> out; | ||
| 133 | + for (const auto s : categories) { | ||
| 134 | + out.emplace(s); | ||
| 135 | + } | ||
| 136 | + return out; | ||
| 137 | + }; | ||
| 129 | 138 | // Attach a new NodeTraceWriter only if this function hasn't been called | |
| 130 | 139 | // before. | |
| 131 | 140 | if (tracing_file_writer_.IsDefaultHandle()) { | |
| 132 | - std::vector<std::string> categories = | ||
| 133 | - SplitString(per_process::cli_options->trace_event_categories, ','); | ||
| 141 | + using std::string_view_literals::operator""sv; | ||
| 142 | + const std::vector<std::string_view> categories = | ||
| 143 | + SplitString(per_process::cli_options->trace_event_categories, ","sv); | ||
| 134 | 144 | ||
| 135 | 145 | tracing_file_writer_ = tracing_agent_->AddClient( | |
| 136 | - std::set<std::string>(std::make_move_iterator(categories.begin()), | ||
| 137 | - std::make_move_iterator(categories.end())), | ||
| 146 | + convert_to_set(categories), | ||
| 138 | 147 | std::unique_ptr<tracing::AsyncTraceWriter>( | |
| 139 | 148 | new tracing::NodeTraceWriter( | |
| 140 | 149 | per_process::cli_options->trace_event_file_pattern)), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ | |||
| 9 | 9 | #include <algorithm> | |
| 10 | 10 | #include <filesystem> | |
| 11 | 11 | #include <string> | |
| 12 | + #include <string_view> | ||
| 12 | 13 | #include <vector> | |
| 13 | 14 | ||
| 14 | 15 | namespace { | |
@@ -74,8 +75,9 @@ namespace permission { | |||
| 74 | 75 | // allow = '*' | |
| 75 | 76 | // allow = '/tmp/,/home/example.js' | |
| 76 | 77 | void FSPermission::Apply(const std::string& allow, PermissionScope scope) { | |
| 77 | - for (const auto& res : SplitString(allow, ',')) { | ||
| 78 | - if (res == "*") { | ||
| 78 | + using std::string_view_literals::operator""sv; | ||
| 79 | + for (const std::string_view res : SplitString(allow, ","sv)) { | ||
| 80 | + if (res == "*"sv) { | ||
| 79 | 81 | if (scope == PermissionScope::kFileSystemRead) { | |
| 80 | 82 | deny_all_in_ = false; | |
| 81 | 83 | allow_all_in_ = true; | |
@@ -85,7 +87,7 @@ void FSPermission::Apply(const std::string& allow, PermissionScope scope) { | |||
| 85 | 87 | } | |
| 86 | 88 | return; | |
| 87 | 89 | } | |
| 88 | - GrantAccess(scope, res); | ||
| 90 | + GrantAccess(scope, std::string(res.data(), res.size())); | ||
| 89 | 91 | } | |
| 90 | 92 | } | |
| 91 | 93 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -165,19 +165,21 @@ std::string GetHumanReadableProcessName() { | |||
| 165 | 165 | return SPrintF("%s[%d]", GetProcessTitle("Node.js"), uv_os_getpid()); | |
| 166 | 166 | } | |
| 167 | 167 | ||
| 168 | - std::vector<std::string> SplitString(const std::string& in, | ||
| 169 | - char delim, | ||
| 170 | - bool skipEmpty) { | ||
| 171 | - std::vector<std::string> out; | ||
| 172 | - if (in.empty()) | ||
| 173 | - return out; | ||
| 174 | - std::istringstream in_stream(in); | ||
| 175 | - while (in_stream.good()) { | ||
| 176 | - std::string item; | ||
| 177 | - std::getline(in_stream, item, delim); | ||
| 178 | - if (item.empty() && skipEmpty) continue; | ||
| 179 | - out.emplace_back(std::move(item)); | ||
| 168 | + std::vector<std::string_view> SplitString(const std::string_view in, | ||
| 169 | + const std::string_view delim) { | ||
| 170 | + std::vector<std::string_view> out; | ||
| 171 | + | ||
| 172 | + for (auto first = in.data(), second = in.data(), last = first + in.size(); | ||
| 173 | + second != last && first != last; | ||
| 174 | + first = second + 1) { | ||
| 175 | + second = | ||
| 176 | + std::find_first_of(first, last, std::cbegin(delim), std::cend(delim)); | ||
| 177 | + | ||
| 178 | + if (first != second) { | ||
| 179 | + out.emplace_back(first, second - first); | ||
| 180 | + } | ||
| 180 | 181 | } | |
| 182 | + | ||
| 181 | 183 | return out; | |
| 182 | 184 | } | |
| 183 | 185 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -676,9 +676,8 @@ struct FunctionDeleter { | |||
| 676 | 676 | template <typename T, void (*function)(T*)> | |
| 677 | 677 | using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer; | |
| 678 | 678 | ||
| 679 | - std::vector<std::string> SplitString(const std::string& in, | ||
| 680 | - char delim, | ||
| 681 | - bool skipEmpty = true); | ||
| 679 | + std::vector<std::string_view> SplitString(const std::string_view in, | ||
| 680 | + const std::string_view delim); | ||
| 682 | 681 | ||
| 683 | 682 | inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context, | |
| 684 | 683 | std::string_view str, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments