From f5f40c808858abfc30daba71207150b7b68a36fc 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 591d13537990ce..6faab3096542d4 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1106,8 +1106,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)