Skip to content

Commit 02dbae6

Browse files
Trottaddaleax
authored andcommitted
buffer: refactor Buffer.prototype.inspect()
Replace toString().match().join() with toString().replace().trim(). This enables the elimination of a length check becuase replace() will return empty string if Buffer is empty whereas match() returns null. PR-URL: #11600 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 1445e28 commit 02dbae6

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

‎lib/buffer.js‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,10 @@ Buffer.prototype.equals = function equals(b){
521521
Buffer.prototype[internalUtil.customInspectSymbol]=functioninspect(){
522522
varstr='';
523523
varmax=exports.INSPECT_MAX_BYTES;
524-
if(this.length>0){
525-
str=this.toString('hex',0,max).match(/.{2}/g).join(' ');
526-
if(this.length>max)
527-
str+=' ... ';
528-
}
529-
return'<'+this.constructor.name+' '+str+'>';
524+
str=this.toString('hex',0,max).replace(/(.{2})/g,'$1 ').trim();
525+
if(this.length>max)
526+
str+=' ... ';
527+
return`<${this.constructor.name}${str}>`;
530528
};
531529
Buffer.prototype.inspect=Buffer.prototype[internalUtil.customInspectSymbol];
532530

0 commit comments

Comments
(0)