Skip to content

Commit

Permalink
refactor(console): prepare for noUncheckedIndexedAccess (denoland#4269
Browse files Browse the repository at this point in the history
)
  • Loading branch information
eryue0220 authored Feb 2, 2024
1 parent 9d0317a commit b77b51a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion console/_run_length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)!));
Expand Down
8 changes: 5 additions & 3 deletions console/unicode_width.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b77b51a

Please sign in to comment.