Skip to content

Commit

Permalink
src: replace SplitString with built-in
Browse files Browse the repository at this point in the history
PR-URL: #54990
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
anonrig authored and targos committed Feb 11, 2025
1 parent f06ee4c commit 6b398d6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ void DebugOptions::CheckOptions(std::vector<std::string>* errors,
"`node --inspect-brk` instead.");
}

using std::string_view_literals::operator""sv;
const std::vector<std::string_view> destinations =
SplitString(inspect_publish_uid_string, ","sv);
using std::operator""sv;
auto entries = std::views::split(inspect_publish_uid_string, ","sv);
inspect_publish_uid.console = false;
inspect_publish_uid.http = false;
for (const std::string_view destination : destinations) {
for (const auto& entry : entries) {
std::string_view destination(entry.data(), entry.size());
if (destination == "stderr"sv) {
inspect_publish_uid.console = true;
} else if (destination == "http"sv) {
inspect_publish_uid.http = true;
} else {
errors->push_back("--inspect-publish-uid destination can be "
"stderr or http");
errors->emplace_back("--inspect-publish-uid destination can be "
"stderr or http");
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/node_v8_platform-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ struct V8Platform {

inline void StartTracingAgent() {
constexpr auto convert_to_set =
[](std::vector<std::string_view> categories) -> std::set<std::string> {
[](auto& categories) -> std::set<std::string> {
std::set<std::string> out;
for (const auto& s : categories) {
out.emplace(s);
out.emplace(std::string(s.data(), s.size()));
}
return out;
};
// Attach a new NodeTraceWriter only if this function hasn't been called
// before.
if (tracing_file_writer_.IsDefaultHandle()) {
using std::string_view_literals::operator""sv;
const std::vector<std::string_view> categories =
SplitString(per_process::cli_options->trace_event_categories, ","sv);
using std::operator""sv;
auto categories = std::views::split(
per_process::cli_options->trace_event_categories, ","sv);

tracing_file_writer_ = tracing_agent_->AddClient(
convert_to_set(categories),
Expand Down
18 changes: 0 additions & 18 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,6 @@ std::string GetHumanReadableProcessName() {
return SPrintF("%s[%d]", GetProcessTitle("Node.js"), uv_os_getpid());
}

std::vector<std::string_view> SplitString(const std::string_view in,
const std::string_view delim) {
std::vector<std::string_view> out;

for (auto first = in.data(), second = in.data(), last = first + in.size();
second != last && first != last;
first = second + 1) {
second =
std::find_first_of(first, last, std::cbegin(delim), std::cend(delim));

if (first != second) {
out.emplace_back(first, second - first);
}
}

return out;
}

void ThrowErrStringTooLong(Isolate* isolate) {
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));
}
Expand Down
2 changes: 0 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,6 @@ using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
inline v8::Maybe<void> FromV8Array(v8::Local<v8::Context> context,
v8::Local<v8::Array> js_array,
std::vector<v8::Global<v8::Value>>* out);
std::vector<std::string_view> SplitString(const std::string_view in,
const std::string_view delim);

inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
std::string_view str,
Expand Down

0 comments on commit 6b398d6

Please sign in to comment.