Skip to content

Commit 43335d5

Browse files
committed
src: replace splitstring with built-in
1 parent 53cba82 commit 43335d5

File tree

4 files changed

+11
-32
lines changed

4 files changed

+11
-32
lines changed

src/node_options.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ void DebugOptions::CheckOptions(std::vector<std::string>* errors,
5252
"`node --inspect-brk` instead.");
5353
}
5454

55-
using std::string_view_literals::operator""sv;
56-
const std::vector<std::string_view> destinations =
57-
SplitString(inspect_publish_uid_string, ","sv);
55+
using std::operator""sv;
56+
auto destinations = std::views::split(inspect_publish_uid_string, ","sv);
5857
inspect_publish_uid.console = false;
5958
inspect_publish_uid.http = false;
60-
for (const std::string_view destination : destinations) {
61-
if (destination == "stderr"sv) {
59+
for (const auto destination : destinations) {
60+
std::string_view _dest(destination.data(), destination.size());
61+
if (_dest == "stderr"sv) {
6262
inspect_publish_uid.console = true;
63-
} else if (destination == "http"sv) {
63+
} else if (_dest == "http"sv) {
6464
inspect_publish_uid.http = true;
6565
} else {
66-
errors->push_back("--inspect-publish-uid destination can be "
66+
errors->emplace_back("--inspect-publish-uid destination can be "
6767
"stderr or http");
6868
}
6969
}

src/node_v8_platform-inl.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,18 @@ struct V8Platform {
128128

129129
inline void StartTracingAgent() {
130130
constexpr auto convert_to_set =
131-
[](std::vector<std::string_view> categories) -> std::set<std::string> {
131+
[](auto& categories) -> std::set<std::string> {
132132
std::set<std::string> out;
133133
for (const auto& s : categories) {
134-
out.emplace(s);
134+
out.emplace(std::string(s.data(), s.size()));
135135
}
136136
return out;
137137
};
138138
// Attach a new NodeTraceWriter only if this function hasn't been called
139139
// before.
140140
if (tracing_file_writer_.IsDefaultHandle()) {
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);
141+
using std::operator""sv;
142+
auto categories = std::views::split(per_process::cli_options->trace_event_categories, ","sv);
144143

145144
tracing_file_writer_ = tracing_agent_->AddClient(
146145
convert_to_set(categories),

src/util.cc

-18
Original file line numberDiff line numberDiff line change
@@ -220,24 +220,6 @@ std::string GetHumanReadableProcessName() {
220220
return SPrintF("%s[%d]", GetProcessTitle("Node.js"), uv_os_getpid());
221221
}
222222

223-
std::vector<std::string_view> SplitString(const std::string_view in,
224-
const std::string_view delim) {
225-
std::vector<std::string_view> out;
226-
227-
for (auto first = in.data(), second = in.data(), last = first + in.size();
228-
second != last && first != last;
229-
first = second + 1) {
230-
second =
231-
std::find_first_of(first, last, std::cbegin(delim), std::cend(delim));
232-
233-
if (first != second) {
234-
out.emplace_back(first, second - first);
235-
}
236-
}
237-
238-
return out;
239-
}
240-
241223
void ThrowErrStringTooLong(Isolate* isolate) {
242224
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));
243225
}

src/util.h

-2
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,6 @@ using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
703703
inline v8::Maybe<void> FromV8Array(v8::Local<v8::Context> context,
704704
v8::Local<v8::Array> js_array,
705705
std::vector<v8::Global<v8::Value>>* out);
706-
std::vector<std::string_view> SplitString(const std::string_view in,
707-
const std::string_view delim);
708706

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

0 commit comments

Comments
 (0)