Skip to content

Commit 3c40b75

Browse files
committed
add more docs
1 parent e734940 commit 3c40b75

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/packets/packet.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,16 +374,20 @@ Packet.prototype.readString = function (len) {
374374
return this.buffer.utf8Slice(this.offset - len, this.offset);
375375
};
376376

377-
var minus = '-'.charCodeAt(0);
378-
var plus = '+'.charCodeAt(0);
379-
380377
// The whole reason parse* function below exist
381-
// is because String creation is relatively expensive, and if we have
378+
// is because String creation is relatively expensive (at least with V8), and if we have
382379
// a buffer with "12345" content ideally we would like to bypass intermediate
383380
// "12345" string creation and directly build 12345 number out of
384381
// <Buffer 31 32 33 34 35> data.
385-
// In my benchmarks "parse" methods
382+
// In my benchmarks the difference is ~25M 8-digit numbers per second vs
383+
// 4.5 M using Number(packet.readLengthCodedString())
384+
// not used when size is close to max precision as series of *10 accumulate error
385+
// and approximate result mihgt be diffreent from (approximate as well) Number(bigNumStringValue))
386+
// In the futire node version if speed difference is smaller parse* functions might be removed
387+
// don't consider them as Packet public API
386388

389+
var minus = '-'.charCodeAt(0);
390+
var plus = '+'.charCodeAt(0);
387391

388392
Packet.prototype.parseInt = function (len, supportBigNumbers) {
389393

@@ -475,7 +479,7 @@ Packet.prototype.parseIntNoBigCheck = function (len) {
475479
result += this.buffer[this.offset] - 48;
476480
this.offset++;
477481
}
478-
return result * sign;
482+
return result * sign;
479483
};
480484

481485
// copy-paste from https://github.com/felixge/node-mysql/blob/master/lib/protocol/Parser.js

0 commit comments

Comments
 (0)