|
@@ -908,6 +908,7 @@ function DataViewReader( buffer ) {
|
|
this.dv = new DataView( buffer );
|
|
this.dv = new DataView( buffer );
|
|
this.offset = 0;
|
|
this.offset = 0;
|
|
this._textDecoder = new TextDecoder();
|
|
this._textDecoder = new TextDecoder();
|
|
|
|
+ this._bytes = new Uint8Array( buffer );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1065,35 +1066,34 @@ DataViewReader.prototype = {
|
|
|
|
|
|
if ( size === 0 ) return;
|
|
if ( size === 0 ) return;
|
|
|
|
|
|
- // note: safari 9 doesn't support Uint8Array.indexOf; create intermediate array instead
|
|
|
|
- var a = [];
|
|
|
|
-
|
|
|
|
- if ( size ) {
|
|
|
|
|
|
+ const start = this.offset;
|
|
|
|
|
|
- for ( var i = 0; i < size; i ++ ) {
|
|
|
|
|
|
+ let result;
|
|
|
|
+ let length;
|
|
|
|
|
|
- a[ i ] = this.getUint8();
|
|
|
|
|
|
+ if ( size ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ length = size;
|
|
|
|
+ result = this._textDecoder.decode( new Uint8Array( this.dv.buffer, start, size ) );
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- var currentChar;
|
|
|
|
- var len = 0;
|
|
|
|
-
|
|
|
|
- while ( currentChar !== 0 ) {
|
|
|
|
|
|
+ // use 1:1 mapping of buffer to avoid redundant new array creation.
|
|
|
|
+ length = this._bytes.indexOf( 0, start ) - start;
|
|
|
|
|
|
- currentChar = this.getUint8();
|
|
|
|
- if ( currentChar !== 0 ) a.push( currentChar );
|
|
|
|
- len ++;
|
|
|
|
|
|
+ result = this._textDecoder.decode( new Uint8Array( this.dv.buffer, start, length ) );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ // account for null byte in length
|
|
|
|
+ length++;
|
|
|
|
|
|
- if ( ! isEven( len + 1 ) ) this.getUint8(); // if string with terminating nullbyte is uneven, extra nullbyte is added
|
|
|
|
|
|
+ // if string with terminating nullbyte is uneven, extra nullbyte is added, skip that too
|
|
|
|
+ length += length % 2;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- return this._textDecoder.decode( new Uint8Array( a ) );
|
|
|
|
|
|
+ this.skip( length );
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|