The Buffer.byteLength() accepts Buffer instance as parameter, so
the code can be simplified to Buffer.byteLength(value, encoding)
without type check.
make -j4 test
net, _http_outgoing, child_process
lib: clarify get byteLength
Did you check relevant benchmarks with this? Since byteLength() is quite large and thus currently uninlineable, I could see this possibly causing a perf hit for non-strings?
LGTM if performance remains steady.
Ok, I just checked with benchmark/http/simple.js (e.g. type=buffer length=4 chunks=4 c=50) for example and with that there does seem to be a slight perf hit with the changes in this PR (I'm seeing roughly 2-7% without doing a long drawn-out comparison).
type=buffer length=4 chunks=4 c=50
Because of that I'd have to say -1 for me.
The changes to the net module are probably ok, because most people probably don't use bytesWritten that often. Besides, there's already a forEach() in that getter so it's already somewhat slower because of that...