buffer: optimize common encoding cases
authorTrevor Norris <trev.norris@gmail.com>
Tue, 10 Sep 2013 02:39:21 +0000 (19:39 -0700)
committerTrevor Norris <trev.norris@gmail.com>
Tue, 10 Sep 2013 02:39:21 +0000 (19:39 -0700)
commit59dac01e4eaebd01714b6640ae2cd656796147fb
treea9d5243004fc75daabf9df4bff4c933baf3bca36
parent204228b57f06ece34b61d69c5e3b58218bbfed0e
buffer: optimize common encoding cases

String#toLowerCase() is incredibly slow and was costing a 15-30%
performance hit for Buffers less than 1KB. Now instead it'll attempt to
find the correct encoding directly from the passed encoding, only then
afterwards it'll lowercase.

The optimization for not passing any encoding at all is still at the top
of the method.

At most this may add 10% performance hit for passing a mixed case
encoding.
lib/buffer.js