Skip to content

Commit

Permalink
src: use simdutf utf8 to utf16 instead of icu
Browse files Browse the repository at this point in the history
PR-URL: #46471
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
anonrig authored and MylesBorins committed Feb 18, 2023
1 parent 00b81c7 commit f35f6d2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 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>

Expand Down Expand Up @@ -289,10 +290,12 @@ Deletable* MainThreadInterface::GetObjectIfExists(int id) {
}

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());
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

0 comments on commit f35f6d2

Please sign in to comment.