From b00102e035c0ee58b198c3d8e8309f528f3d9967 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 13 Aug 2024 18:19:05 +0200 Subject: [PATCH] buffer: optimize for common encodings PR-URL: https://github.com/nodejs/node/pull/54319 Reviewed-By: Yagiz Nizipli Reviewed-By: James M Snell Reviewed-By: Bryan English --- lib/buffer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/buffer.js b/lib/buffer.js index 4e6031afdb3919..ac562b6865dea9 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)