Skip to content

Commit

Permalink
buffer: refactor Buffer.prototype.inspect()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Trott committed Mar 2, 2017
1 parent 48583c4 commit 03b1a2d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,10 @@ Buffer.prototype.equals = function equals(b) {
Buffer.prototype[internalUtil.customInspectSymbol] = function inspect() {
var str = '';
var max = exports.INSPECT_MAX_BYTES;
if (this.length > 0) {
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
if (this.length > max)
str += ' ... ';
}
return '<' + this.constructor.name + ' ' + str + '>';
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
if (this.length > max)
str += ' ... ';
return `<${this.constructor.name} ${str}>`;
};
Buffer.prototype.inspect = Buffer.prototype[internalUtil.customInspectSymbol];

Expand Down

0 comments on commit 03b1a2d

Please sign in to comment.