@@ -583,8 +583,9 @@ Buffer.concat = function concat(list, length) {
583583 if ( length === undefined ) {
584584 length = 0 ;
585585 for ( let i = 0 ; i < list . length ; i ++ ) {
586- if ( list [ i ] . length ) {
587- length += list [ i ] . length ;
586+ const bufLength = list [ i ] . length ;
587+ if ( bufLength ) {
588+ length += bufLength ;
588589 }
589590 }
590591 } else {
@@ -602,15 +603,16 @@ Buffer.concat = function concat(list, length) {
602603 `list[${ i } ]` , [ 'Buffer' , 'Uint8Array' ] , list [ i ] ) ;
603604 }
604605
605- if ( buf . length === 0 || pos >= length ) {
606- // Empty buf or destination is full; subsequent copies are no-ops.
606+ const bufLength = buf . length ;
607+ if ( bufLength === 0 || pos >= length ) {
608+ // Empty buf, or destination is full and subsequent copies are no-ops.
607609 // We don't break to preserve compatibility and throw if isUint8Array fails.
608610 continue ;
609611 }
610612
611613 const available = length - pos ;
612- const toCopy = buf . length > available ? available : buf . length ;
613- if ( toCopy === buf . length ) {
614+ const toCopy = bufLength > available ? available : bufLength ;
615+ if ( toCopy === bufLength ) {
614616 TypedArrayPrototypeSet ( buffer , buf , pos ) ;
615617 } else {
616618 TypedArrayPrototypeSet ( buffer , TypedArrayPrototypeSubarray ( buf , 0 , toCopy ) , pos ) ;
0 commit comments