@@ -374,16 +374,20 @@ Packet.prototype.readString = function (len) {
374
374
return this . buffer . utf8Slice ( this . offset - len , this . offset ) ;
375
375
} ;
376
376
377
- var minus = '-' . charCodeAt ( 0 ) ;
378
- var plus = '+' . charCodeAt ( 0 ) ;
379
-
380
377
// 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
382
379
// a buffer with "12345" content ideally we would like to bypass intermediate
383
380
// "12345" string creation and directly build 12345 number out of
384
381
// <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
386
388
389
+ var minus = '-' . charCodeAt ( 0 ) ;
390
+ var plus = '+' . charCodeAt ( 0 ) ;
387
391
388
392
Packet . prototype . parseInt = function ( len , supportBigNumbers ) {
389
393
@@ -475,7 +479,7 @@ Packet.prototype.parseIntNoBigCheck = function (len) {
475
479
result += this . buffer [ this . offset ] - 48 ;
476
480
this . offset ++ ;
477
481
}
478
- return result * sign ;
482
+ return result * sign ;
479
483
} ;
480
484
481
485
// copy-paste from https://github.com/felixge/node-mysql/blob/master/lib/protocol/Parser.js
0 commit comments