fixing whitespaces
This commit is contained in:
@@ -156,7 +156,7 @@ const old_wcwidth = (function(opts) {
|
|||||||
|
|
||||||
describe('wcwidth', () => {
|
describe('wcwidth', () => {
|
||||||
it('same as old implementation for BMP and individual higher', () => {
|
it('same as old implementation for BMP and individual higher', () => {
|
||||||
for (let i=0; i<65536; ++i)
|
for (let i = 0; i < 65536; ++i)
|
||||||
assert.equal(wcwidth(i), old_wcwidth(i));
|
assert.equal(wcwidth(i), old_wcwidth(i));
|
||||||
// test some individual higher to fullfill branching
|
// test some individual higher to fullfill branching
|
||||||
assert.equal(wcwidth(0x10A01), old_wcwidth(0x10A01));
|
assert.equal(wcwidth(0x10A01), old_wcwidth(0x10A01));
|
||||||
@@ -166,16 +166,16 @@ describe('wcwidth', () => {
|
|||||||
it('new is at least 10 times faster', () => {
|
it('new is at least 10 times faster', () => {
|
||||||
let start_new = new Date().getTime();
|
let start_new = new Date().getTime();
|
||||||
let x = 0;
|
let x = 0;
|
||||||
for (let runs=0; runs<1; ++runs)
|
for (let runs = 0; runs < 1; ++runs)
|
||||||
for (let i=0; i<65536; ++i)
|
for (let i=0; i<65536; ++i)
|
||||||
x = wcwidth(i);
|
x = wcwidth(i);
|
||||||
let end_new = new Date().getTime();
|
let end_new = new Date().getTime();
|
||||||
let start_old = new Date().getTime();
|
let start_old = new Date().getTime();
|
||||||
let y = 0;
|
let y = 0;
|
||||||
for (let runs=0; runs<1; ++runs)
|
for (let runs = 0; runs < 1; ++runs)
|
||||||
for (let i=0; i<65536; ++i)
|
for (let i = 0; i < 65536; ++i)
|
||||||
y = old_wcwidth(i);
|
y = old_wcwidth(i);
|
||||||
let end_old = new Date().getTime();
|
let end_old = new Date().getTime();
|
||||||
assert.equal(((end_new-start_new)*10 < (end_old-start_old)), true);
|
assert.equal(((end_new-start_new) * 10 < (end_old-start_old)), true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+6
-6
@@ -1601,21 +1601,21 @@ export const wcwidth = (function(opts) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
let table = new Uint8Array(16384);
|
let table = new Uint8Array(16384);
|
||||||
for (let i=0; i<16384; ++i) {
|
for (let i = 0; i < 16384; ++i) {
|
||||||
let j = i * 4;
|
let j = i * 4;
|
||||||
let num = 0;
|
let num = 0;
|
||||||
num |= (wcwidthBMP(j+3));
|
num |= (wcwidthBMP(j + 3));
|
||||||
num <<= 2;
|
num <<= 2;
|
||||||
num |= (wcwidthBMP(j+2));
|
num |= (wcwidthBMP(j + 2));
|
||||||
num <<= 2;
|
num <<= 2;
|
||||||
num |= (wcwidthBMP(j+1));
|
num |= (wcwidthBMP(j + 1));
|
||||||
num <<= 2;
|
num <<= 2;
|
||||||
num |= (wcwidthBMP(j));
|
num |= (wcwidthBMP(j));
|
||||||
table[i] = num;
|
table[i] = num;
|
||||||
}
|
}
|
||||||
return function (num) {
|
return function (num) {
|
||||||
num = num|0;
|
num = num | 0;
|
||||||
return (num<65536) ? (table[num>>2] >> ((num & 3) * 2))&3 : wcwidthHigh(num);
|
return (num < 65536) ? (table[num >> 2] >> ((num & 3) * 2)) & 3 : wcwidthHigh(num);
|
||||||
}
|
}
|
||||||
})({nul: 0, control: 0}); // configurable options
|
})({nul: 0, control: 0}); // configurable options
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user