mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
perf(napi/parser, linter/plugins): raw transfer use String.fromCharCode in string decoding (#21018)
Small optimization to raw transfer string deserialization. Use `String.fromCharCode`instead of `String.fromCodePoint`. [Benchmarking](https://github.com/overlookmotel/oxc-raw-str-bench) showed it's slightly faster, as it's simpler - doesn't need to handle astral code points.
This commit is contained in:
1 parent
ac39e5158d
commit
9f494c3bc8
10 files changed
+20
-20
No files matched your search
@@ -16,7 +16,7 @@ let uint8,
|
||||
|
||||
const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
||||
decodeStr = textDecoder.decode.bind(textDecoder),
|
||||
{ fromCodePoint } = String,
|
||||
{ fromCharCode } = String,
|
||||
NodeProto = Object.create(Object.prototype, {
|
||||
loc: {
|
||||
get() {
|
||||
@@ -5894,7 +5894,7 @@ function deserializeStr(pos) {
|
||||
c;
|
||||
do {
|
||||
c = uint8[pos++];
|
||||
if (c < 128) out += fromCodePoint(c);
|
||||
if (c < 128) out += fromCharCode(c);
|
||||
else {
|
||||
out += decodeStr(uint8.subarray(pos - 1, end));
|
||||
break;
|
||||
|
||||
@@ -5,7 +5,7 @@ let uint8, uint32, float64, sourceText, sourceIsAscii, sourceEndPos, firstNonAsc
|
||||
|
||||
const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
||||
decodeStr = textDecoder.decode.bind(textDecoder),
|
||||
{ fromCodePoint } = String;
|
||||
{ fromCharCode } = String;
|
||||
|
||||
export function deserialize(buffer, sourceText, sourceByteLen) {
|
||||
sourceEndPos = sourceByteLen;
|
||||
@@ -4557,7 +4557,7 @@ function deserializeStr(pos) {
|
||||
c;
|
||||
do {
|
||||
c = uint8[pos++];
|
||||
if (c < 128) out += fromCodePoint(c);
|
||||
if (c < 128) out += fromCharCode(c);
|
||||
else {
|
||||
out += decodeStr(uint8.subarray(pos - 1, end));
|
||||
break;
|
||||
|
||||
@@ -12,7 +12,7 @@ let uint8,
|
||||
|
||||
const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
||||
decodeStr = textDecoder.decode.bind(textDecoder),
|
||||
{ fromCodePoint } = String;
|
||||
{ fromCharCode } = String;
|
||||
|
||||
export function deserialize(buffer, sourceText, sourceByteLen) {
|
||||
sourceEndPos = sourceByteLen;
|
||||
@@ -5094,7 +5094,7 @@ function deserializeStr(pos) {
|
||||
c;
|
||||
do {
|
||||
c = uint8[pos++];
|
||||
if (c < 128) out += fromCodePoint(c);
|
||||
if (c < 128) out += fromCharCode(c);
|
||||
else {
|
||||
out += decodeStr(uint8.subarray(pos - 1, end));
|
||||
break;
|
||||
|
||||
@@ -5,7 +5,7 @@ let uint8, uint32, float64, sourceText, sourceIsAscii, sourceEndPos, firstNonAsc
|
||||
|
||||
const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
||||
decodeStr = textDecoder.decode.bind(textDecoder),
|
||||
{ fromCodePoint } = String;
|
||||
{ fromCharCode } = String;
|
||||
|
||||
export function deserialize(buffer, sourceText, sourceByteLen) {
|
||||
sourceEndPos = sourceByteLen;
|
||||
@@ -5099,7 +5099,7 @@ function deserializeStr(pos) {
|
||||
c;
|
||||
do {
|
||||
c = uint8[pos++];
|
||||
if (c < 128) out += fromCodePoint(c);
|
||||
if (c < 128) out += fromCharCode(c);
|
||||
else {
|
||||
out += decodeStr(uint8.subarray(pos - 1, end));
|
||||
break;
|
||||
|
||||
@@ -12,7 +12,7 @@ let uint8,
|
||||
|
||||
const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
||||
decodeStr = textDecoder.decode.bind(textDecoder),
|
||||
{ fromCodePoint } = String;
|
||||
{ fromCharCode } = String;
|
||||
|
||||
export function deserialize(buffer, sourceText, sourceByteLen) {
|
||||
sourceEndPos = sourceByteLen;
|
||||
@@ -5639,7 +5639,7 @@ function deserializeStr(pos) {
|
||||
c;
|
||||
do {
|
||||
c = uint8[pos++];
|
||||
if (c < 128) out += fromCodePoint(c);
|
||||
if (c < 128) out += fromCharCode(c);
|
||||
else {
|
||||
out += decodeStr(uint8.subarray(pos - 1, end));
|
||||
break;
|
||||
|
||||
@@ -5,7 +5,7 @@ let uint8, uint32, float64, sourceText, sourceIsAscii, sourceEndPos, firstNonAsc
|
||||
|
||||
const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
||||
decodeStr = textDecoder.decode.bind(textDecoder),
|
||||
{ fromCodePoint } = String;
|
||||
{ fromCharCode } = String;
|
||||
|
||||
export function deserialize(buffer, sourceText, sourceByteLen) {
|
||||
sourceEndPos = sourceByteLen;
|
||||
@@ -4866,7 +4866,7 @@ function deserializeStr(pos) {
|
||||
c;
|
||||
do {
|
||||
c = uint8[pos++];
|
||||
if (c < 128) out += fromCodePoint(c);
|
||||
if (c < 128) out += fromCharCode(c);
|
||||
else {
|
||||
out += decodeStr(uint8.subarray(pos - 1, end));
|
||||
break;
|
||||
|
||||
@@ -12,7 +12,7 @@ let uint8,
|
||||
|
||||
const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
||||
decodeStr = textDecoder.decode.bind(textDecoder),
|
||||
{ fromCodePoint } = String;
|
||||
{ fromCharCode } = String;
|
||||
|
||||
export function deserialize(buffer, sourceText, sourceByteLen) {
|
||||
sourceEndPos = sourceByteLen;
|
||||
@@ -5430,7 +5430,7 @@ function deserializeStr(pos) {
|
||||
c;
|
||||
do {
|
||||
c = uint8[pos++];
|
||||
if (c < 128) out += fromCodePoint(c);
|
||||
if (c < 128) out += fromCharCode(c);
|
||||
else {
|
||||
out += decodeStr(uint8.subarray(pos - 1, end));
|
||||
break;
|
||||
|
||||
@@ -5,7 +5,7 @@ let uint8, uint32, float64, sourceText, sourceIsAscii, sourceEndPos, firstNonAsc
|
||||
|
||||
const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
||||
decodeStr = textDecoder.decode.bind(textDecoder),
|
||||
{ fromCodePoint } = String;
|
||||
{ fromCharCode } = String;
|
||||
|
||||
export function deserialize(buffer, sourceText, sourceByteLen) {
|
||||
sourceEndPos = sourceByteLen;
|
||||
@@ -5439,7 +5439,7 @@ function deserializeStr(pos) {
|
||||
c;
|
||||
do {
|
||||
c = uint8[pos++];
|
||||
if (c < 128) out += fromCodePoint(c);
|
||||
if (c < 128) out += fromCharCode(c);
|
||||
else {
|
||||
out += decodeStr(uint8.subarray(pos - 1, end));
|
||||
break;
|
||||
|
||||
@@ -12,7 +12,7 @@ let uint8,
|
||||
|
||||
const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
||||
decodeStr = textDecoder.decode.bind(textDecoder),
|
||||
{ fromCodePoint } = String;
|
||||
{ fromCharCode } = String;
|
||||
|
||||
export function deserialize(buffer, sourceText, sourceByteLen) {
|
||||
sourceEndPos = sourceByteLen;
|
||||
@@ -6003,7 +6003,7 @@ function deserializeStr(pos) {
|
||||
c;
|
||||
do {
|
||||
c = uint8[pos++];
|
||||
if (c < 128) out += fromCodePoint(c);
|
||||
if (c < 128) out += fromCharCode(c);
|
||||
else {
|
||||
out += decodeStr(uint8.subarray(pos - 1, end));
|
||||
break;
|
||||
|
||||
@@ -150,7 +150,7 @@ fn generate_deserializers(
|
||||
|
||||
const textDecoder = new TextDecoder('utf-8', {{ ignoreBOM: true }}),
|
||||
decodeStr = textDecoder.decode.bind(textDecoder),
|
||||
{{ fromCodePoint }} = String;
|
||||
{{ fromCharCode }} = String;
|
||||
|
||||
/* IF LOC */
|
||||
const NodeProto = Object.create(Object.prototype, {{
|
||||
@@ -948,7 +948,7 @@ static STR_DESERIALIZER_BODY: &str = "
|
||||
do {
|
||||
c = uint8[pos++];
|
||||
if (c < 0x80) {
|
||||
out += fromCodePoint(c);
|
||||
out += fromCharCode(c);
|
||||
} else {
|
||||
out += decodeStr(uint8.subarray(pos - 1, end));
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user