From 177b7314cf62f6c268eef9f71657aba9c93385ed Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 14 Feb 2018 23:42:57 +0100 Subject: [PATCH] buffer: improve Buffer#fill performance 1) This improves the performance for Buffer#fill by using shortcuts. 2) It also ports throwing errors to JS. That way they contain the proper error code. 3) Using negative `end` values will from now on result in an error instead of just doing nothing. 4) Passing in `null` as encoding is from now on accepted as 'utf8'. PR-URL: https://github.com/nodejs/node/pull/18790 Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum Reviewed-By: Matteo Collina --- doc/api/buffer.md | 3 + lib/buffer.js | 88 +++++++++-------- lib/internal/util.js | 2 +- src/node_buffer.cc | 17 ++-- test/parallel/test-buffer-fill.js | 98 ++++--------------- .../test-internal-util-normalizeencoding.js | 13 ++- 6 files changed, 85 insertions(+), 136 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 225726316aa..510848c3b04 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -1202,6 +1202,9 @@ console.log(buf1.equals(buf3));