speedup utf32ToString conversion

This commit is contained in:
Jörg Breitbart
2019-01-03 02:55:11 +01:00
parent 1fb1f556b1
commit 27b91f6b00
2 changed files with 10 additions and 12 deletions
+1 -1
View File
@@ -567,7 +567,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
if (j >= length
|| (code = data[j]) < 0x20
|| (code > 0x7f && code <= 0x9f)) {
osc += utf32ToString(data.subarray(i, j));
osc += utf32ToString(data, i, j);
i = j - 1;
break;
}
+9 -11
View File
@@ -1,5 +1,3 @@
import { stringFromCodePoint } from '../core/input/TextDecoder';
/**
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
* @license MIT
@@ -54,17 +52,17 @@ export function concat<T extends TypedArray>(a: T, b: T): T {
/**
* Convert UTF32 char codes into JS string.
* Note the typed array is not limited to Uint16Array, make sure to align
* the values to 0-65535 integer for other typed array types, otherwise
* the conversion will fail.
*/
export function utf32ToString<T extends TypedArray>(data: T): string {
if ((String as any).fromCodePoint) {
return (String as any).fromCodePoint.apply(null, data);
}
export function utf32ToString<T extends TypedArray>(data: T, start: number = 0, end: number = data.length): string {
let result = '';
for (let i = 0; i < data.length; ++i) {
result += stringFromCodePoint(data[i]);
let cp;
for (let i = start; i < end; ++i) {
if ((cp = data[i]) > 0xFFFF) {
cp -= 0x10000;
result += String.fromCharCode((cp >> 10) + 0xD800) + String.fromCharCode((cp % 0x400) + 0xDC00);
} else {
result += String.fromCharCode(cp);
}
}
return result;
}