refactor(console): prepare for noUncheckedIndexedAccess (#4269)

This commit is contained in:
cin 2024-02-02 15:42:48 +08:00 committed by GitHub
parent 9d0317a5be
commit b77b51aa70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -32,7 +32,7 @@ export function runLengthDecode({ d, r }: { d: string; r: string }) {
let out = "";
for (const [i, ch] of [...runLengths].entries()) {
out += data[i].repeat(ch.codePointAt(0)!);
out += data[i]!.repeat(ch.codePointAt(0)!);
}
return Uint8Array.from([...out].map((x) => x.codePointAt(0)!));

View File

@ -8,9 +8,11 @@ let tables: Uint8Array[] | null = null;
function lookupWidth(cp: number) {
if (!tables) tables = data.tables.map(runLengthDecode);
const t1Offset = tables[0][(cp >> 13) & 0xff];
const t2Offset = tables[1][128 * t1Offset + ((cp >> 6) & 0x7f)];
const packedWidths = tables[2][16 * t2Offset + ((cp >> 2) & 0xf)];
const t1Offset = (tables[0] as Uint8Array)[(cp >> 13) & 0xff] as number;
const t2Offset =
(tables[1] as Uint8Array)[128 * t1Offset + ((cp >> 6) & 0x7f)] as number;
const packedWidths =
(tables[2] as Uint8Array)[16 * t2Offset + ((cp >> 2) & 0xf)] as number;
const width = (packedWidths >> (2 * (cp & 0b11))) & 0b11;