stream: micro-optimize high water mark calculation
authorBen Noordhuis <info@bnoordhuis.nl>
Thu, 20 Aug 2015 20:29:57 +0000 (22:29 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 24 Aug 2015 18:24:13 +0000 (20:24 +0200)
commit3af8e451f272f1398acf7336f9eff0c64340ffe3
tree026e37605fef21affc0305c9794be7889125e30a
parent1a3f4a87b68eb5a906564b05f3774ea768fc510c
stream: micro-optimize high water mark calculation

Don't iterate over all 32 bits, use some hacker's delight bit twiddling
to compute the next power of two.

The logic can be reduced to `n = 1 << 32 - Math.clz32(n)` but then it
can't easily be backported to v2.x; Math.clz32() was added in V8 4.3.

PR-URL: https://github.com/nodejs/node/pull/2479
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
lib/_stream_readable.js