Commit b07852d1 authored by Сковорода Никита Андреевич's avatar Сковорода Никита Андреевич Committed by Trivikram Kamat
Browse files

buffer: use FastBuffer when fill is set to 0

A large number of libraries seem to use Buffer.alloc(size, 0)
instead of just Buffer.alloc(size).

We don't need to follow the "create unsafe buffer and fill it" path
(i.e. actually allocate and perform fill) in that situation, that is
better handled by Uint8Array constructor.

Buffer.alloc(size) and Buffer.alloc(size, 0) are equivalent, so
use the same code path.

Not performing the zero-fill manually and having the underlying memory
allocator do it for us can improve speed and reduce the memory usage
for situations where Buffer.alloc(size, 0) is used.

PR-URL: https://github.com/nodejs/node/pull/21989


Reviewed-By: default avatarAnna Henningsen <anna@addaleax.net>
Reviewed-By: default avatarRuben Bridgewater <ruben@bridgewater.de>
Reviewed-By: default avatarTrivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: default avatarMinwoo Jung <minwoo@nodesource.com>
Reviewed-By: default avatarColin Ihrig <cjihrig@gmail.com>
Reviewed-By: default avatarJames M Snell <jasnell@gmail.com>
Reviewed-By: default avatarTiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: default avatarGireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: default avatarTobias Nießen <tniessen@tnie.de>
parent 5be9b1d7
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment