mirror of
https://git.proxmox.com/git/mirror_xterm.js
synced 2025-10-05 04:51:57 +00:00
some fixes
- commenting the bit shifts - switching to Uint32Array - conditional for TypedArray - fixing Math.floor slowdown in bisearch
This commit is contained in:
parent
5d87b54390
commit
1232c00dd1
@ -1553,7 +1553,7 @@ export const wcwidth = (function(opts) {
|
|||||||
if (ucs < data[0][0] || ucs > data[max][1])
|
if (ucs < data[0][0] || ucs > data[max][1])
|
||||||
return false;
|
return false;
|
||||||
while (max >= min) {
|
while (max >= min) {
|
||||||
mid = Math.floor((min + max) / 2);
|
mid = (min + max) >> 1;
|
||||||
if (ucs > data[mid][1])
|
if (ucs > data[mid][1])
|
||||||
min = mid + 1;
|
min = mid + 1;
|
||||||
else if (ucs < data[mid][0])
|
else if (ucs < data[mid][0])
|
||||||
@ -1600,22 +1600,43 @@ export const wcwidth = (function(opts) {
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
let table = new Uint8Array(16384);
|
// lookup table for BMP
|
||||||
for (let i = 0; i < 16384; ++i) {
|
const CODEPOINTS = 65536; // BMP holds 65536 codepoints
|
||||||
let j = i * 4;
|
const BITWIDTH = 2; // a codepoint can have a width of 0, 1 or 2
|
||||||
|
const ITEMSIZE = 32; // using uint32_t
|
||||||
|
const CONTAINERSIZE = CODEPOINTS * BITWIDTH / ITEMSIZE;
|
||||||
|
const CODEPOINTS_PER_ITEM = ITEMSIZE / BITWIDTH;
|
||||||
|
const table = (typeof Uint32Array === 'undefined')
|
||||||
|
? new Array(CONTAINERSIZE)
|
||||||
|
: new Uint32Array(CONTAINERSIZE);
|
||||||
|
for (let i = 0; i < CONTAINERSIZE; ++i) {
|
||||||
let num = 0;
|
let num = 0;
|
||||||
num |= (wcwidthBMP(j + 3));
|
let pos = CODEPOINTS_PER_ITEM;
|
||||||
num <<= 2;
|
while (pos--)
|
||||||
num |= (wcwidthBMP(j + 2));
|
num = (num << 2) | wcwidthBMP(CODEPOINTS_PER_ITEM * i + pos);
|
||||||
num <<= 2;
|
|
||||||
num |= (wcwidthBMP(j + 1));
|
|
||||||
num <<= 2;
|
|
||||||
num |= (wcwidthBMP(j));
|
|
||||||
table[i] = num;
|
table[i] = num;
|
||||||
}
|
}
|
||||||
|
// get width from lookup table for num < 65536:
|
||||||
|
// position in container : num / CODEPOINTS_PER_ITEM
|
||||||
|
// ==> n = table[Math.floor(num / 16)]
|
||||||
|
// ==> n = table[num >> 4]
|
||||||
|
// 16 codepoints per number: FFEEDDCCBBAA99887766554433221100
|
||||||
|
// position in number : (num % CODEPOINTS_PER_ITEM) * BITWIDTH
|
||||||
|
// ==> m = (n % 16) * 2
|
||||||
|
// ==> m = (num & 15) << 1
|
||||||
|
// right shift to position m
|
||||||
|
// ==> n = n >> m e.g. m=12 000000000000FFEEDDCCBBAA99887766
|
||||||
|
// we are only interested in 2 LSBs, cut off higher
|
||||||
|
// ==> n = n & 3 e.g. 000000000000000000000000000000XX
|
||||||
return function (num) {
|
return function (num) {
|
||||||
num = num | 0;
|
num = num | 0; // get asm.js like optimization under V8
|
||||||
return (num < 65536) ? (table[num >> 2] >> ((num & 3) * 2)) & 3 : wcwidthHigh(num);
|
if (num < 32)
|
||||||
|
return opts.control;
|
||||||
|
else if (num < 127)
|
||||||
|
return 1;
|
||||||
|
else if (num < 65536)
|
||||||
|
return table[num >> 4] >> ((num & 15) << 1) & 3;
|
||||||
|
// do a full search for high codepoints
|
||||||
|
else return wcwidthHigh(num);
|
||||||
};
|
};
|
||||||
})({nul: 0, control: 0}); // configurable options
|
})({nul: 0, control: 0}); // configurable options
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user