@@ -70,6 +70,8 @@ var INF_POSITIVE_BUFFER = [
7070
7171var EXPONENT_REGEX = / ^ ( [ - + ] ) ? ( \d + ) ? $ / ;
7272
73+ var utils = require ( './parser/utils' ) ;
74+
7375// Detect if the value is a digit
7476var isDigit = function ( value ) {
7577 return ! isNaN ( parseInt ( value , 10 ) ) ;
@@ -143,7 +145,7 @@ var lessThan = function(left, right) {
143145} ;
144146
145147// var longtoHex = function(value) {
146- // var buffer = new Buffer (8);
148+ // var buffer = utils.allocBuffer (8);
147149// var index = 0;
148150// // Encode the low 64 bits of the decimal
149151// // Encode low bits
@@ -160,7 +162,7 @@ var lessThan = function(left, right) {
160162// };
161163
162164// var int32toHex = function(value) {
163- // var buffer = new Buffer (4);
165+ // var buffer = utils.allocBuffer (4);
164166// var index = 0;
165167// // Encode the low 64 bits of the decimal
166168// // Encode low bits
@@ -265,17 +267,17 @@ Decimal128.fromString = function(string) {
265267 // Check if user passed Infinity or NaN
266268 if ( ! isDigit ( string [ index ] ) && string [ index ] !== '.' ) {
267269 if ( string [ index ] === 'i' || string [ index ] === 'I' ) {
268- return new Decimal128 ( new Buffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
270+ return new Decimal128 ( utils . toBuffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
269271 } else if ( string [ index ] === 'N' ) {
270- return new Decimal128 ( new Buffer ( NAN_BUFFER ) ) ;
272+ return new Decimal128 ( utils . toBuffer ( NAN_BUFFER ) ) ;
271273 }
272274 }
273275
274276 // Read all the digits
275277 while ( isDigit ( string [ index ] ) || string [ index ] === '.' ) {
276278 if ( string [ index ] === '.' ) {
277279 if ( sawRadix ) {
278- return new Decimal128 ( new Buffer ( NAN_BUFFER ) ) ;
280+ return new Decimal128 ( utils . toBuffer ( NAN_BUFFER ) ) ;
279281 }
280282
281283 sawRadix = true ;
@@ -320,7 +322,7 @@ Decimal128.fromString = function(string) {
320322
321323 // No digits read
322324 if ( ! match || ! match [ 2 ] ) {
323- return new Decimal128 ( new Buffer ( NAN_BUFFER ) ) ;
325+ return new Decimal128 ( utils . toBuffer ( NAN_BUFFER ) ) ;
324326 }
325327
326328 // Get exponent
@@ -332,7 +334,7 @@ Decimal128.fromString = function(string) {
332334
333335 // Return not a number
334336 if ( string [ index ] ) {
335- return new Decimal128 ( new Buffer ( NAN_BUFFER ) ) ;
337+ return new Decimal128 ( utils . toBuffer ( NAN_BUFFER ) ) ;
336338 }
337339
338340 // Done reading input
@@ -380,7 +382,7 @@ Decimal128.fromString = function(string) {
380382 exponent = EXPONENT_MAX ;
381383 break ;
382384 } else {
383- return new Decimal128 ( new Buffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
385+ return new Decimal128 ( utils . toBuffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
384386 }
385387 }
386388
@@ -412,7 +414,7 @@ Decimal128.fromString = function(string) {
412414 exponent = EXPONENT_MAX ;
413415 break ;
414416 } else {
415- return new Decimal128 ( new Buffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
417+ return new Decimal128 ( utils . toBuffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
416418 }
417419 }
418420 }
@@ -462,7 +464,7 @@ Decimal128.fromString = function(string) {
462464 digits [ dIdx ] = 1 ;
463465 } else {
464466 return new Decimal128 (
465- new Buffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER )
467+ utils . toBuffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER )
466468 ) ;
467469 }
468470 }
@@ -547,7 +549,7 @@ Decimal128.fromString = function(string) {
547549 }
548550
549551 // Encode into a buffer
550- var buffer = new Buffer ( 16 ) ;
552+ var buffer = utils . allocBuffer ( 16 ) ;
551553 index = 0 ;
552554
553555 // Encode the low 64 bits of the decimal
0 commit comments