File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -98,10 +98,20 @@ export function safeStringFromCharCode(units: Array<number> | Uint16Array) {
9898 return result ;
9999}
100100
101+ const MIN_TEXT_DECODER_STRING_LENGTH = 32 ;
102+ const defaultEncoding = "utf-8" ;
103+ const sharedTextDecoder = typeof TextDecoder !== "undefined" ? new TextDecoder ( defaultEncoding ) : null ;
104+
101105export function utf8Decode ( bytes : Uint8Array , inputOffset : number , byteLength : number ) : string {
102106 let offset = inputOffset ;
103- const out : Array < number > = [ ] ;
104107 const end = offset + byteLength ;
108+
109+ if ( sharedTextDecoder !== null && byteLength > MIN_TEXT_DECODER_STRING_LENGTH ) {
110+ const stringBytes = bytes . subarray ( offset , end ) ;
111+ return sharedTextDecoder . decode ( stringBytes ) ;
112+ }
113+
114+ const out : Array < number > = [ ] ;
105115 while ( offset < end ) {
106116 const byte1 = bytes [ offset ++ ] ;
107117 if ( ( byte1 & 0x80 ) === 0 ) {
You can’t perform that action at this time.
0 commit comments