Browse Source

Avoid unnecessary buffer to string conversion.

Speeds up the benchmark below by about 680% (0.5s versus 3.4s on my Core 2 Duo).

    var crypto = require('crypto');
    var hash = crypto.createHash('sha1');
    var data = new Buffer(1024);
    for (var i = 0; i < 128 * 1024; ++i) hash.update(data);

Fixes #2494.
v0.7.4-release
Ben Noordhuis 13 years ago
parent
commit
9a79bb694e
  1. 4
      src/node.cc

4
src/node.cc

@ -1046,6 +1046,10 @@ ssize_t DecodeBytes(v8::Handle<v8::Value> val, enum encoding encoding) {
return -1;
}
if (encoding == BINARY && Buffer::HasInstance(val)) {
return Buffer::Length(val->ToObject());
}
Local<String> str = val->ToString();
if (encoding == UTF8) return str->Utf8Length();

Loading…
Cancel
Save