Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: use simdutf utf8 to utf16 instead of icu #46471

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/inspector/main_thread_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#include "env-inl.h"
#include "node_mutex.h"
#include "v8-inspector.h"
#include "simdutf.h"
#include "util-inl.h"
#include "v8-inspector.h"

#include <unicode/unistr.h>
anonrig marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -288,11 +289,13 @@ Deletable* MainThreadInterface::GetObjectIfExists(int id) {
return iterator->second.get();
}

std::unique_ptr<StringBuffer> Utf8ToStringView(const std::string& message) {
icu::UnicodeString utf16 = icu::UnicodeString::fromUTF8(
icu::StringPiece(message.data(), message.length()));
StringView view(reinterpret_cast<const uint16_t*>(utf16.getBuffer()),
utf16.length());
std::unique_ptr<StringBuffer> Utf8ToStringView(const std::string_view message) {
size_t expected_u16_length =
simdutf::utf16_length_from_utf8(message.data(), message.length());
MaybeStackBuffer<char16_t> buffer(expected_u16_length);
size_t utf16_length = simdutf::convert_utf8_to_utf16(
message.data(), message.length(), buffer.out());
StringView view(reinterpret_cast<uint16_t*>(buffer.out()), utf16_length);
return StringBuffer::create(view);
}

Expand Down
2 changes: 1 addition & 1 deletion src/inspector/main_thread_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Deletable {
};

std::unique_ptr<v8_inspector::StringBuffer> Utf8ToStringView(
const std::string& message);
const std::string_view message);

using MessageQueue = std::deque<std::unique_ptr<Request>>;

Expand Down