@@ -256,27 +256,28 @@ const mappers = {
256256 }
257257
258258 const decode = ( arr , start , end , stream ) => {
259- let res = ''
259+ const o16 = new Uint16Array ( end - start + 2 ) // err in eof + lead from state
260+ let oi = 0
260261 let i = start
261262 const pushback = [ ] // local and auto-cleared
262263
263264 // First, dump everything until EOF
264265 // Same as the full loop, but without EOF handling
265266 while ( i < end || pushback . length > 0 ) {
266267 const c = bytes ( pushback , pushback . length > 0 ? pushback . pop ( ) : arr [ i ++ ] )
267- if ( c !== undefined ) res += String . fromCodePoint ( c )
268+ if ( c !== undefined ) o16 [ oi ++ ] = c // 16-bit
268269 }
269270
270271 // Then, dump EOF. This needs the same loop as the characters can be pushed back
271272 if ( ! stream ) {
272273 while ( i <= end || pushback . length > 0 ) {
273274 if ( i < end || pushback . length > 0 ) {
274275 const c = bytes ( pushback , pushback . length > 0 ? pushback . pop ( ) : arr [ i ++ ] )
275- if ( c !== undefined ) res += String . fromCodePoint ( c )
276+ if ( c !== undefined ) o16 [ oi ++ ] = c // 16-bit
276277 } else {
277278 const c = eof ( pushback )
278279 if ( c === null ) break // clean exit
279- res += String . fromCodePoint ( c )
280+ o16 [ oi ++ ] = c
280281 }
281282 }
282283 }
@@ -290,7 +291,7 @@ const mappers = {
290291 out = false
291292 }
292293
293- return res
294+ return decodeUCS2 ( o16 , oi )
294295 }
295296
296297 return { decode, isAscii : ( ) => false }
0 commit comments