Skip to content

Commit 6b398d6

Browse files
anonrigtargos
authored andcommitted
src: replace SplitString with built-in
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>
1 parent f06ee4c commit 6b398d6

File tree

4 files changed

+11
-31
lines changed

4 files changed

+11
-31
lines changed

src/node_options.cc

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

56-
using std::string_view_literals::operator""sv;
57-
const std::vector<std::string_view> destinations =
58-
SplitString(inspect_publish_uid_string, ","sv);
56+
using std::operator""sv;
57+
auto entries = std::views::split(inspect_publish_uid_string, ","sv);
5958
inspect_publish_uid.console = false;
6059
inspect_publish_uid.http = false;
61-
for (const std::string_view destination : destinations) {
60+
for (const auto& entry : entries) {
61+
std::string_view destination(entry.data(), entry.size());
6262
if (destination == "stderr"sv) {
6363
inspect_publish_uid.console = true;
6464
} else if (destination == "http"sv) {
6565
inspect_publish_uid.http = true;
6666
} else {
67-
errors->push_back("--inspect-publish-uid destination can be "
68-
"stderr or http");
67+
errors->emplace_back("--inspect-publish-uid destination can be "
68+
"stderr or http");
6969
}
7070
}
7171
}

src/node_v8_platform-inl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,19 @@ 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(
143+
per_process::cli_options->trace_event_categories, ","sv);
144144

145145
tracing_file_writer_ = tracing_agent_->AddClient(
146146
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
@@ -715,8 +715,6 @@ using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
715715
inline v8::Maybe<void> FromV8Array(v8::Local<v8::Context> context,
716716
v8::Local<v8::Array> js_array,
717717
std::vector<v8::Global<v8::Value>>* out);
718-
std::vector<std::string_view> SplitString(const std::string_view in,
719-
const std::string_view delim);
720718

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

0 commit comments

Comments
 (0)