refactor(sqlite): reuse text decoding for ASCII identifiers (#16848)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-05 05:41:27 +08:00
1 parent 218ae34dca
commit d2342c949d
1 file changed
+2 -23
+2 -23
View File
@@ -360,29 +360,8 @@ const asciiLower = (
bytes: Uint8Array,
encoding: DatabaseEncoding,
): string | undefined => {
if (encoding === "UTF-8") {
let text = "";
for (const byte of bytes) {
if (byte >= 0x80) return undefined;
text += String.fromCharCode(
byte >= 0x41 && byte <= 0x5a ? byte + 0x20 : byte,
);
}
return text;
}
if (bytes.length % 2 !== 0) return undefined;
const lowFirst = encoding === "UTF-16le";
let text = "";
for (let index = 0; index < bytes.length; index += 2) {
const unit = lowFirst
? bytes[index]! | (bytes[index + 1]! << 8)
: (bytes[index]! << 8) | bytes[index + 1]!;
if (unit >= 0x80) return undefined;
text += String.fromCharCode(
unit >= 0x41 && unit <= 0x5a ? unit + 0x20 : unit,
);
}
return text;
const text = LENIENT_TEXT_DECODERS[encoding].decode(bytes);
return /\P{ASCII}/u.test(text) ? undefined : text.toLowerCase();
};
const readPrimaryKeyIndexName = (