Cache the length of `buffer` before you start the loop: `for(var i=0; len=buffer.length; i<len; i++) {`