src: replace `SplitString` with built-in · nodejs/node@6b398d6 · GitHub
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

4 files changed

Lines changed: 11 additions & 31 deletions

File tree

src/node_options.cc

Lines changed: 6 additions & 6 deletions

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
@@ -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

Lines changed: 0 additions & 2 deletions

0 commit comments

Comments
 (0)