@@ -1489,6 +1489,35 @@ uint32_t FastWriteString(Local<Value> receiver,
1489
1489
1490
1490
static v8::CFunction fast_write_string (v8::CFunction::Make(FastWriteString));
1491
1491
1492
+ uint32_t FastWriteStringUTF8 (
1493
+ Local<Value> receiver,
1494
+ const v8::FastApiTypedArray<uint8_t >& dst,
1495
+ const v8::FastOneByteString& src,
1496
+ uint32_t offset,
1497
+ uint32_t max_length,
1498
+ // NOLINTNEXTLINE(runtime/references) This is V8 api.
1499
+ v8::FastApiCallbackOptions& options) {
1500
+ uint8_t * dst_data;
1501
+ CHECK (dst.getStorageIfAligned (&dst_data));
1502
+ CHECK (offset <= dst.length ());
1503
+ CHECK (dst.length () - offset <= std::numeric_limits<uint32_t >::max ());
1504
+
1505
+ const auto size = std::min (
1506
+ {static_cast <uint32_t >(dst.length () - offset), max_length, src.length });
1507
+
1508
+ if (!simdutf::validate_utf8 (src.data , size)) {
1509
+ options.fallback = true ;
1510
+ return 0 ;
1511
+ }
1512
+
1513
+ memcpy (dst_data + offset, src.data , size);
1514
+
1515
+ return size;
1516
+ }
1517
+
1518
+ static v8::CFunction fast_write_string_utf8 (
1519
+ v8::CFunction::Make (FastWriteStringUTF8));
1520
+
1492
1521
void Initialize (Local<Object> target,
1493
1522
Local<Value> unused,
1494
1523
Local<Context> context,
@@ -1568,7 +1597,7 @@ void Initialize(Local<Object> target,
1568
1597
target,
1569
1598
" utf8WriteStatic" ,
1570
1599
SlowWriteString<UTF8>,
1571
- &fast_write_string );
1600
+ &fast_write_string_utf8 );
1572
1601
1573
1602
SetMethod (context, target, " getZeroFillToggle" , GetZeroFillToggle);
1574
1603
}
@@ -1615,6 +1644,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
1615
1644
registry->Register (SlowWriteString<UTF8>);
1616
1645
registry->Register (fast_write_string.GetTypeInfo ());
1617
1646
registry->Register (FastWriteString);
1647
+ registry->Register (fast_write_string_utf8.GetTypeInfo ());
1648
+ registry->Register (FastWriteStringUTF8);
1618
1649
registry->Register (StringWrite<ASCII>);
1619
1650
registry->Register (StringWrite<BASE64>);
1620
1651
registry->Register (StringWrite<BASE64URL>);
0 commit comments