buffer: optimize Buffer.byteLength
authorBrendan Ashworth <brendan.ashworth@me.com>
Sat, 16 May 2015 02:24:34 +0000 (19:24 -0700)
committerBrendan Ashworth <brendan.ashworth@me.com>
Fri, 22 May 2015 22:31:03 +0000 (15:31 -0700)
commit9da168b71fb729635ad71e839630480e815623d0
tree0f508d18ed0180c410dbb62b77a15dc9ab919a71
parent2a71f02988244b6299db8fe8ba3cc0491793acfc
buffer: optimize Buffer.byteLength

Buffer.byteLength is important for speed because it is called whenever a
new Buffer is created from a string.

This commit optimizes Buffer.byteLength execution by:
- moving base64 length calculation into JS-land, which is now much
  faster
- remove redundant code and streamline the UTF8 length calculation

It also adds a benchmark and better tests.

PR-URL: https://github.com/nodejs/io.js/pull/1713
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
benchmark/buffers/buffer-bytelength.js [new file with mode: 0644]
lib/buffer.js
src/node_buffer.cc
test/parallel/test-buffer-bytelength.js [new file with mode: 0644]
test/parallel/test-buffer.js