Skip to content

Commit d829961

Browse files
anonrigaduh95
authored andcommitted
src: replace SplitString with built-in
PR-URL: #54990 Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent f600010 commit d829961

File tree

4 files changed

+11
-31
lines changed

4 files changed

+11
-31
lines changed

src/node_options.cc

Lines changed: 6 additions & 6 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,24 +198,6 @@ std::string GetHumanReadableProcessName() {
198198
return SPrintF("%s[%d]", GetProcessTitle("Node.js"), uv_os_getpid());
199199
}
200200

201-
std::vector<std::string_view> SplitString(const std::string_view in,
202-
const std::string_view delim) {
203-
std::vector<std::string_view> out;
204-
205-
for (auto first = in.data(), second = in.data(), last = first + in.size();
206-
second != last && first != last;
207-
first = second + 1) {
208-
second =
209-
std::find_first_of(first, last, std::cbegin(delim), std::cend(delim));
210-
211-
if (first != second) {
212-
out.emplace_back(first, second - first);
213-
}
214-
}
215-
216-
return out;
217-
}
218-
219201
void ThrowErrStringTooLong(Isolate* isolate) {
220202
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));
221203
}

src/util.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,6 @@ using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
714714
inline v8::Maybe<void> FromV8Array(v8::Local<v8::Context> context,
715715
v8::Local<v8::Array> js_array,
716716
std::vector<v8::Global<v8::Value>>* out);
717-
std::vector<std::string_view> SplitString(const std::string_view in,
718-
const std::string_view delim);
719717

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

0 commit comments

Comments
 (0)