diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-10-18 17:13:30 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-10-18 17:13:30 -0700 |
commit | 1b2f6f9e29bf7137e177b8d9b600fe558d36f512 (patch) | |
tree | c67553632967b08349b9b5e83a897d189dafd8f2 /deps/v8/src/conversions.cc | |
parent | 5d400cfd3a2a9faf27a88bf82f33a57f78fa65af (diff) | |
download | node-1b2f6f9e29bf7137e177b8d9b600fe558d36f512.tar.gz |
Upgrade V8 to 2.5.0
Diffstat (limited to 'deps/v8/src/conversions.cc')
-rw-r--r-- | deps/v8/src/conversions.cc | 68 |
1 files changed, 17 insertions, 51 deletions
diff --git a/deps/v8/src/conversions.cc b/deps/v8/src/conversions.cc index f15a804ef..790e807ae 100644 --- a/deps/v8/src/conversions.cc +++ b/deps/v8/src/conversions.cc @@ -34,6 +34,7 @@ #include "dtoa.h" #include "factory.h" #include "scanner.h" +#include "strtod.h" namespace v8 { namespace internal { @@ -103,8 +104,6 @@ static bool SubStringEquals(Iterator* current, } -extern "C" double gay_strtod(const char* s00, const char** se); - // Maximum number of significant digits in decimal representation. // The longest possible double in decimal representation is // (2^53 - 1) * 2 ^ -1074 that is (2 ^ 53 - 1) * 5 ^ 1074 / 10 ^ 1074 @@ -353,8 +352,9 @@ static double InternalStringToInt(Iterator current, EndMark end, int radix) { } ASSERT(buffer_pos < kBufferSize); - buffer[buffer_pos++] = '\0'; - return sign ? -gay_strtod(buffer, NULL) : gay_strtod(buffer, NULL); + buffer[buffer_pos] = '\0'; + Vector<const char> buffer_vector(buffer, buffer_pos); + return sign ? -Strtod(buffer_vector, 0) : Strtod(buffer_vector, 0); } // The following code causes accumulating rounding error for numbers greater @@ -462,7 +462,6 @@ static double InternalStringToDouble(Iterator current, ++current; if (!AdvanceToNonspace(¤t, end)) return JUNK_STRING_VALUE; } else if (*current == '-') { - buffer[buffer_pos++] = '-'; ++current; if (!AdvanceToNonspace(¤t, end)) return JUNK_STRING_VALUE; sign = true; @@ -478,8 +477,8 @@ static double InternalStringToDouble(Iterator current, return JUNK_STRING_VALUE; } - ASSERT(buffer_pos == 0 || buffer[0] == '-'); - return buffer_pos > 0 ? -V8_INFINITY : V8_INFINITY; + ASSERT(buffer_pos == 0); + return sign ? -V8_INFINITY : V8_INFINITY; } bool leading_zero = false; @@ -496,7 +495,6 @@ static double InternalStringToDouble(Iterator current, return JUNK_STRING_VALUE; // "0x". } - bool sign = (buffer_pos > 0 && buffer[0] == '-'); return InternalStringToIntDouble<4>(current, end, sign, @@ -533,6 +531,9 @@ static double InternalStringToDouble(Iterator current, } if (*current == '.') { + if (octal && !allow_trailing_junk) return JUNK_STRING_VALUE; + if (octal) goto parsing_done; + ++current; if (current == end) { if (significant_digits == 0 && !leading_zero) { @@ -553,16 +554,16 @@ static double InternalStringToDouble(Iterator current, } } - ASSERT(buffer_pos < kBufferSize); - buffer[buffer_pos++] = '.'; + // We don't emit a '.', but adjust the exponent instead. fractional_part = true; - // There is the fractional part. + // There is a fractional part. while (*current >= '0' && *current <= '9') { if (significant_digits < kMaxSignificantDigits) { ASSERT(buffer_pos < kBufferSize); buffer[buffer_pos++] = static_cast<char>(*current); significant_digits++; + exponent--; } else { // Ignore insignificant digits in the fractional part. nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; @@ -638,60 +639,25 @@ static double InternalStringToDouble(Iterator current, exponent += insignificant_digits; if (octal) { - bool sign = buffer[0] == '-'; - int start_pos = (sign ? 1 : 0); - - return InternalStringToIntDouble<3>(buffer + start_pos, + return InternalStringToIntDouble<3>(buffer, buffer + buffer_pos, sign, allow_trailing_junk); } if (nonzero_digit_dropped) { - if (insignificant_digits) buffer[buffer_pos++] = '.'; buffer[buffer_pos++] = '1'; - } - - // If the number has no more than kMaxDigitsInInt digits and doesn't have - // fractional part it could be parsed faster (without checks for - // spaces, overflow, etc.). - const int kMaxDigitsInInt = 9 * sizeof(int) / 4; // NOLINT - - if (exponent != 0) { - ASSERT(buffer_pos < kBufferSize); - buffer[buffer_pos++] = 'e'; - if (exponent < 0) { - ASSERT(buffer_pos < kBufferSize); - buffer[buffer_pos++] = '-'; - exponent = -exponent; - } - if (exponent > 999) exponent = 999; // Result will be Infinity or 0 or -0. - - const int exp_digits = 3; - for (int i = 0; i < exp_digits; i++) { - buffer[buffer_pos + exp_digits - 1 - i] = '0' + exponent % 10; - exponent /= 10; - } - ASSERT(exponent == 0); - buffer_pos += exp_digits; - } else if (!fractional_part && significant_digits <= kMaxDigitsInInt) { - if (significant_digits == 0) return SignedZero(sign); - ASSERT(buffer_pos > 0); - int num = 0; - int start_pos = (buffer[0] == '-' ? 1 : 0); - for (int i = start_pos; i < buffer_pos; i++) { - ASSERT(buffer[i] >= '0' && buffer[i] <= '9'); - num = 10 * num + (buffer[i] - '0'); - } - return static_cast<double>(start_pos == 0 ? num : -num); + exponent--; } ASSERT(buffer_pos < kBufferSize); buffer[buffer_pos] = '\0'; - return gay_strtod(buffer, NULL); + double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); + return sign? -converted: converted; } + double StringToDouble(String* str, int flags, double empty_string_val) { StringShape shape(str); if (shape.IsSequentialAscii()) { |