mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
speedup utf32ToString conversion
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user