Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 24 additions & 11 deletions apps/oxlint/src-js/generated/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ let uint8,
uint32,
float64,
sourceText,
sourceIsAscii,
sourceStartPos,
firstNonAsciiPos,
parent = null,
Expand Down Expand Up @@ -42,14 +41,12 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLen, getLocInput, de
uint32 = buffer.uint32;
float64 = buffer.float64;
sourceText = sourceTextInput;
sourceIsAscii = sourceText.length === sourceByteLen;
if (!sourceIsAscii) {
firstNonAsciiPos = sourceByteLen;
for (let i = sourceStartPos, e = sourceStartPos + sourceByteLen; i < e; i++)
if (uint8[i] >= 128) {
firstNonAsciiPos = i - sourceStartPos;
break;
}
if (sourceText.length === sourceByteLen) firstNonAsciiPos = sourceStartPos + sourceByteLen;
else {
let i = sourceStartPos,
sourceEndPos = sourceStartPos + sourceByteLen;
for (; i < sourceEndPos && uint8[i] < 128; i++);
firstNonAsciiPos = i;
}
getLoc = getLocInput;
return deserialize(uint32[536870900]);
Expand Down Expand Up @@ -5883,11 +5880,27 @@ function deserializeStr(pos) {
len = uint32[pos32 + 2];
if (len === 0) return "";
pos = uint32[pos32];
if (pos >= sourceStartPos && (sourceIsAscii || pos - sourceStartPos + len <= firstNonAsciiPos))
let end = pos + len;
// Note: Tried reducing this check to a single branch by making the comparison the equivalent of this Rust:
// `end.wrapping_sub(sourceStartPos) <= firstNonAsciiOffset`.
//
// The JS versions tried were:
// - `((end - sourceStartPos) >>> 0) <= firstNonAsciiOffset`
// - `((end - sourceStartPos) & 0x7FFF_FFFF) <= firstNonAsciiOffset`
// But it turned out that these are both slower by 5-10% on files which are all ASCII.
//
// `>>>` is slower as V8 can't assume result fits in an SMI (which is a 32-bit *signed* integer),
// as result could be greater or equal to `2 ** 31`. So it converts both the comparison's operands to `float64`s
// and does float compare (which is slower than integer compare).
//
// `& 0x7FFF_FFFF` is slower as it has a longer chain of data dependencies than the 2 independent
// branch comparisons.
//
// Both branches are very predictable, so 2 branches wins.
if (pos >= sourceStartPos && end <= firstNonAsciiPos)
return sourceText.substr(pos - sourceStartPos, len);
// Use `TextDecoder` for strings longer than 9 bytes.
// For shorter strings, the byte-by-byte loop below avoids native call overhead.
let end = pos + len;
if (len > 9) return decodeStr(uint8.subarray(pos, end));
// Shorter strings decode by hand to avoid native call
let out = "",
Expand Down
21 changes: 8 additions & 13 deletions napi/parser/src-js/generated/deserialize/js.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/raw_transfer.rs`.

let uint8, uint32, float64, sourceText, sourceIsAscii, sourceEndPos, firstNonAsciiPos;
let uint8, uint32, float64, sourceText, firstNonAsciiPos;

const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
decodeStr = textDecoder.decode.bind(textDecoder),
{ fromCharCode } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
sourceEndPos = sourceByteLen;
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
Expand All @@ -19,14 +18,11 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLen, getLocInput, de
uint32 = buffer.uint32;
float64 = buffer.float64;
sourceText = sourceTextInput;
sourceIsAscii = sourceText.length === sourceByteLen;
if (!sourceIsAscii) {
firstNonAsciiPos = sourceByteLen;
for (let i = 0; i < sourceByteLen; i++)
if (uint8[i] >= 128) {
firstNonAsciiPos = i;
break;
}
if (sourceText.length === sourceByteLen) firstNonAsciiPos = sourceByteLen;
else {
let i = 0;
for (; i < sourceByteLen && uint8[i] < 128; i++);
firstNonAsciiPos = i;
}
return deserialize(uint32[536870900]);
}
Expand Down Expand Up @@ -4546,11 +4542,10 @@ function deserializeStr(pos) {
len = uint32[pos32 + 2];
if (len === 0) return "";
pos = uint32[pos32];
if (pos < sourceEndPos && (sourceIsAscii || pos + len <= firstNonAsciiPos))
return sourceText.substr(pos, len);
let end = pos + len;
if (end <= firstNonAsciiPos) return sourceText.substr(pos, len);
// Use `TextDecoder` for strings longer than 9 bytes.
// For shorter strings, the byte-by-byte loop below avoids native call overhead.
let end = pos + len;
if (len > 9) return decodeStr(uint8.subarray(pos, end));
// Shorter strings decode by hand to avoid native call
let out = "",
Expand Down
21 changes: 7 additions & 14 deletions napi/parser/src-js/generated/deserialize/js_parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ let uint8,
uint32,
float64,
sourceText,
sourceIsAscii,
sourceEndPos,
firstNonAsciiPos,
parent = null;

Expand All @@ -15,7 +13,6 @@ const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
{ fromCharCode } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
sourceEndPos = sourceByteLen;
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
Expand All @@ -26,14 +23,11 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLen, getLocInput, de
uint32 = buffer.uint32;
float64 = buffer.float64;
sourceText = sourceTextInput;
sourceIsAscii = sourceText.length === sourceByteLen;
if (!sourceIsAscii) {
firstNonAsciiPos = sourceByteLen;
for (let i = 0; i < sourceByteLen; i++)
if (uint8[i] >= 128) {
firstNonAsciiPos = i;
break;
}
if (sourceText.length === sourceByteLen) firstNonAsciiPos = sourceByteLen;
else {
let i = 0;
for (; i < sourceByteLen && uint8[i] < 128; i++);
firstNonAsciiPos = i;
}
return deserialize(uint32[536870900]);
}
Expand Down Expand Up @@ -5083,11 +5077,10 @@ function deserializeStr(pos) {
len = uint32[pos32 + 2];
if (len === 0) return "";
pos = uint32[pos32];
if (pos < sourceEndPos && (sourceIsAscii || pos + len <= firstNonAsciiPos))
return sourceText.substr(pos, len);
let end = pos + len;
if (end <= firstNonAsciiPos) return sourceText.substr(pos, len);
// Use `TextDecoder` for strings longer than 9 bytes.
// For shorter strings, the byte-by-byte loop below avoids native call overhead.
let end = pos + len;
if (len > 9) return decodeStr(uint8.subarray(pos, end));
// Shorter strings decode by hand to avoid native call
let out = "",
Expand Down
21 changes: 8 additions & 13 deletions napi/parser/src-js/generated/deserialize/js_range.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/raw_transfer.rs`.

let uint8, uint32, float64, sourceText, sourceIsAscii, sourceEndPos, firstNonAsciiPos;
let uint8, uint32, float64, sourceText, firstNonAsciiPos;

const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
decodeStr = textDecoder.decode.bind(textDecoder),
{ fromCharCode } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
sourceEndPos = sourceByteLen;
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
Expand All @@ -19,14 +18,11 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLen, getLocInput, de
uint32 = buffer.uint32;
float64 = buffer.float64;
sourceText = sourceTextInput;
sourceIsAscii = sourceText.length === sourceByteLen;
if (!sourceIsAscii) {
firstNonAsciiPos = sourceByteLen;
for (let i = 0; i < sourceByteLen; i++)
if (uint8[i] >= 128) {
firstNonAsciiPos = i;
break;
}
if (sourceText.length === sourceByteLen) firstNonAsciiPos = sourceByteLen;
else {
let i = 0;
for (; i < sourceByteLen && uint8[i] < 128; i++);
firstNonAsciiPos = i;
}
return deserialize(uint32[536870900]);
}
Expand Down Expand Up @@ -5088,11 +5084,10 @@ function deserializeStr(pos) {
len = uint32[pos32 + 2];
if (len === 0) return "";
pos = uint32[pos32];
if (pos < sourceEndPos && (sourceIsAscii || pos + len <= firstNonAsciiPos))
return sourceText.substr(pos, len);
let end = pos + len;
if (end <= firstNonAsciiPos) return sourceText.substr(pos, len);
// Use `TextDecoder` for strings longer than 9 bytes.
// For shorter strings, the byte-by-byte loop below avoids native call overhead.
let end = pos + len;
if (len > 9) return decodeStr(uint8.subarray(pos, end));
// Shorter strings decode by hand to avoid native call
let out = "",
Expand Down
21 changes: 7 additions & 14 deletions napi/parser/src-js/generated/deserialize/js_range_parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ let uint8,
uint32,
float64,
sourceText,
sourceIsAscii,
sourceEndPos,
firstNonAsciiPos,
parent = null;

Expand All @@ -15,7 +13,6 @@ const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
{ fromCharCode } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
sourceEndPos = sourceByteLen;
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
Expand All @@ -26,14 +23,11 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLen, getLocInput, de
uint32 = buffer.uint32;
float64 = buffer.float64;
sourceText = sourceTextInput;
sourceIsAscii = sourceText.length === sourceByteLen;
if (!sourceIsAscii) {
firstNonAsciiPos = sourceByteLen;
for (let i = 0; i < sourceByteLen; i++)
if (uint8[i] >= 128) {
firstNonAsciiPos = i;
break;
}
if (sourceText.length === sourceByteLen) firstNonAsciiPos = sourceByteLen;
else {
let i = 0;
for (; i < sourceByteLen && uint8[i] < 128; i++);
firstNonAsciiPos = i;
}
return deserialize(uint32[536870900]);
}
Expand Down Expand Up @@ -5628,11 +5622,10 @@ function deserializeStr(pos) {
len = uint32[pos32 + 2];
if (len === 0) return "";
pos = uint32[pos32];
if (pos < sourceEndPos && (sourceIsAscii || pos + len <= firstNonAsciiPos))
return sourceText.substr(pos, len);
let end = pos + len;
if (end <= firstNonAsciiPos) return sourceText.substr(pos, len);
// Use `TextDecoder` for strings longer than 9 bytes.
// For shorter strings, the byte-by-byte loop below avoids native call overhead.
let end = pos + len;
if (len > 9) return decodeStr(uint8.subarray(pos, end));
// Shorter strings decode by hand to avoid native call
let out = "",
Expand Down
21 changes: 8 additions & 13 deletions napi/parser/src-js/generated/deserialize/ts.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/raw_transfer.rs`.

let uint8, uint32, float64, sourceText, sourceIsAscii, sourceEndPos, firstNonAsciiPos;
let uint8, uint32, float64, sourceText, firstNonAsciiPos;

const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
decodeStr = textDecoder.decode.bind(textDecoder),
{ fromCharCode } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
sourceEndPos = sourceByteLen;
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
Expand All @@ -19,14 +18,11 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLen, getLocInput, de
uint32 = buffer.uint32;
float64 = buffer.float64;
sourceText = sourceTextInput;
sourceIsAscii = sourceText.length === sourceByteLen;
if (!sourceIsAscii) {
firstNonAsciiPos = sourceByteLen;
for (let i = 0; i < sourceByteLen; i++)
if (uint8[i] >= 128) {
firstNonAsciiPos = i;
break;
}
if (sourceText.length === sourceByteLen) firstNonAsciiPos = sourceByteLen;
else {
let i = 0;
for (; i < sourceByteLen && uint8[i] < 128; i++);
firstNonAsciiPos = i;
}
return deserialize(uint32[536870900]);
}
Expand Down Expand Up @@ -4855,11 +4851,10 @@ function deserializeStr(pos) {
len = uint32[pos32 + 2];
if (len === 0) return "";
pos = uint32[pos32];
if (pos < sourceEndPos && (sourceIsAscii || pos + len <= firstNonAsciiPos))
return sourceText.substr(pos, len);
let end = pos + len;
if (end <= firstNonAsciiPos) return sourceText.substr(pos, len);
// Use `TextDecoder` for strings longer than 9 bytes.
// For shorter strings, the byte-by-byte loop below avoids native call overhead.
let end = pos + len;
if (len > 9) return decodeStr(uint8.subarray(pos, end));
// Shorter strings decode by hand to avoid native call
let out = "",
Expand Down
21 changes: 7 additions & 14 deletions napi/parser/src-js/generated/deserialize/ts_parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ let uint8,
uint32,
float64,
sourceText,
sourceIsAscii,
sourceEndPos,
firstNonAsciiPos,
parent = null;

Expand All @@ -15,7 +13,6 @@ const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
{ fromCharCode } = String;

export function deserialize(buffer, sourceText, sourceByteLen) {
sourceEndPos = sourceByteLen;
let data = deserializeWith(buffer, sourceText, sourceByteLen, null, deserializeRawTransferData);
resetBuffer();
return data;
Expand All @@ -26,14 +23,11 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLen, getLocInput, de
uint32 = buffer.uint32;
float64 = buffer.float64;
sourceText = sourceTextInput;
sourceIsAscii = sourceText.length === sourceByteLen;
if (!sourceIsAscii) {
firstNonAsciiPos = sourceByteLen;
for (let i = 0; i < sourceByteLen; i++)
if (uint8[i] >= 128) {
firstNonAsciiPos = i;
break;
}
if (sourceText.length === sourceByteLen) firstNonAsciiPos = sourceByteLen;
else {
let i = 0;
for (; i < sourceByteLen && uint8[i] < 128; i++);
firstNonAsciiPos = i;
}
return deserialize(uint32[536870900]);
}
Expand Down Expand Up @@ -5419,11 +5413,10 @@ function deserializeStr(pos) {
len = uint32[pos32 + 2];
if (len === 0) return "";
pos = uint32[pos32];
if (pos < sourceEndPos && (sourceIsAscii || pos + len <= firstNonAsciiPos))
return sourceText.substr(pos, len);
let end = pos + len;
if (end <= firstNonAsciiPos) return sourceText.substr(pos, len);
// Use `TextDecoder` for strings longer than 9 bytes.
// For shorter strings, the byte-by-byte loop below avoids native call overhead.
let end = pos + len;
if (len > 9) return decodeStr(uint8.subarray(pos, end));
// Shorter strings decode by hand to avoid native call
let out = "",
Expand Down
Loading
Loading