@@ -1267,13 +1267,15 @@ function swap(b, n, m) {
12671267}
12681268
12691269Buffer . prototype . swap16 = function swap16 ( ) {
1270- // For Buffer.length < 128 , it's generally faster to
1270+ // For Buffer.length <= 32 , it's generally faster to
12711271 // do the swap in javascript. For larger buffers,
12721272 // dropping down to the native code is faster.
1273+ if ( ! isUint8Array ( this ) )
1274+ throw new ERR_INVALID_ARG_TYPE ( 'this' , [ 'Buffer' , 'Uint8Array' ] , this ) ;
12731275 const len = this . length ;
12741276 if ( len % 2 !== 0 )
12751277 throw new ERR_INVALID_BUFFER_SIZE ( '16-bits' ) ;
1276- if ( len < 128 ) {
1278+ if ( len <= 32 ) {
12771279 for ( let i = 0 ; i < len ; i += 2 )
12781280 swap ( this , i , i + 1 ) ;
12791281 return this ;
@@ -1283,13 +1285,15 @@ Buffer.prototype.swap16 = function swap16() {
12831285} ;
12841286
12851287Buffer . prototype . swap32 = function swap32 ( ) {
1286- // For Buffer.length < 192 , it's generally faster to
1288+ // For Buffer.length <= 32 , it's generally faster to
12871289 // do the swap in javascript. For larger buffers,
12881290 // dropping down to the native code is faster.
1291+ if ( ! isUint8Array ( this ) )
1292+ throw new ERR_INVALID_ARG_TYPE ( 'this' , [ 'Buffer' , 'Uint8Array' ] , this ) ;
12891293 const len = this . length ;
12901294 if ( len % 4 !== 0 )
12911295 throw new ERR_INVALID_BUFFER_SIZE ( '32-bits' ) ;
1292- if ( len < 192 ) {
1296+ if ( len <= 32 ) {
12931297 for ( let i = 0 ; i < len ; i += 4 ) {
12941298 swap ( this , i , i + 3 ) ;
12951299 swap ( this , i + 1 , i + 2 ) ;
@@ -1301,13 +1305,15 @@ Buffer.prototype.swap32 = function swap32() {
13011305} ;
13021306
13031307Buffer . prototype . swap64 = function swap64 ( ) {
1304- // For Buffer.length < 192 , it's generally faster to
1308+ // For Buffer.length < 48 , it's generally faster to
13051309 // do the swap in javascript. For larger buffers,
13061310 // dropping down to the native code is faster.
1311+ if ( ! isUint8Array ( this ) )
1312+ throw new ERR_INVALID_ARG_TYPE ( 'this' , [ 'Buffer' , 'Uint8Array' ] , this ) ;
13071313 const len = this . length ;
13081314 if ( len % 8 !== 0 )
13091315 throw new ERR_INVALID_BUFFER_SIZE ( '64-bits' ) ;
1310- if ( len < 192 ) {
1316+ if ( len < 48 ) {
13111317 for ( let i = 0 ; i < len ; i += 8 ) {
13121318 swap ( this , i , i + 7 ) ;
13131319 swap ( this , i + 1 , i + 6 ) ;
0 commit comments