From e6514d4e9e8dc5a3e274c2244e0b2f0b4c77e55a Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 11 Aug 2024 18:14:26 +0200 Subject: [PATCH] buffer: optimize for common encodings --- lib/buffer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/buffer.js b/lib/buffer.js index 4e6031afdb39192..ac562b6865dea9c 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1108,8 +1108,10 @@ Buffer.prototype.write = function write(string, offset, length, encoding) { } } - if (!encoding) + if (!encoding || encoding === 'utf8') return this.utf8Write(string, offset, length); + if (encoding === 'ascii') + return this.asciiWrite(string, offset, length); const ops = getEncodingOps(encoding); if (ops === undefined)