Repository: nodejs/node
Pull request: src: replace splitstring with built-in

Replaces SplitString function with built-in implementation available for C++20

Changed files:
filename: src/node_options.cc
patch: @@ -53,19 +53,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");
     }
   }
 }

filename: src/node_v8_platform-inl.h
patch: @@ -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()));
       }
       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),

filename: src/util.cc
patch: @@ -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));
 }

filename: src/util.h
patch: @@ -715,8 +715,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,