Skip to content

buffer: Preallocate array with buffer length in Buffer#toJSON

Because the final array length is known, it's better to allocate its final length at initialization time to avoid future reallocations.

It also adds an explicit buffer length greater than 0 comparison so it's more readable, avoids the internal ToBoolean call and follows the standard Node.js API format (as it can be checked in other similar structures where 'length > 0' is preferred over 'length')

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

buffer

Merge request reports

Loading