Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: replace splitstring with built-in #54990

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,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()));
lemire marked this conversation as resolved.
Show resolved Hide resolved
}
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 @@ -703,8 +703,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
Loading