File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,20 +51,15 @@ export function getUID(): number {
5151 return ++ uidCounter ;
5252}
5353
54- export function utfDecodeString ( array : Uint16Array ) : string {
55- let string = '' ;
56- const { length } = array ;
57- for ( let i = 0 ; i < length ; i ++ ) {
58- string += String . fromCharCode ( array [ i ] ) ;
59- }
60- return string ;
54+ export function utfDecodeString ( array : Uint32Array ) : string {
55+ return String . fromCodePoint ( ...array ) ;
6156}
6257
63- export function utfEncodeString ( string : string ) : Uint16Array {
64- const array = new Uint16Array ( string . length ) ;
65- const { length } = string ;
66- for ( let i = 0 ; i < length ; i ++ ) {
67- array [ i ] = string . charCodeAt ( i ) ;
68- }
69- return array ;
58+ export function utfEncodeString ( string : string ) : Uint32Array {
59+ // $FlowFixMe Flow's Uint32Array.from's type definition is wrong; first argument of mapFn will be string
60+ return Uint32Array . from ( string , toCodePoint ) ;
61+ }
62+
63+ function toCodePoint ( string : string ) {
64+ return string . codePointAt ( 0 ) ;
7065}
You can’t perform that action at this time.
0 commit comments