| Index: src/conversions.cc
|
| diff --git a/src/conversions.cc b/src/conversions.cc
|
| index 0e5d48b0a4de29aa29925ef667dce6df526de00f..d4180640518279db9a19ab9580f6d15b5800cb80 100644
|
| --- a/src/conversions.cc
|
| +++ b/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<char> buffer_vector(buffer, buffer_pos);
|
| + return sign ? -strtod(buffer_vector, NULL) : strtod(buffer_vector, NULL);
|
| }
|
|
|
| // 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,66 +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;
|
| - }
|
| -
|
| - // The minimal/maximal double is +/-1.7e-308. Given that
|
| - // the buffer contains at most 773 (kMaxSignificantDigits + 1) the
|
| - // minimal possible exponent is hence -(308 + 773)=-1081.
|
| - // Since leading zeros are removed the maximal exponent cannot exceed 308.
|
| - // If the following test triggers the result will be +/-infinity or +/-0.
|
| - if (exponent > 9999) exponent = 9999;
|
| -
|
| - const int exp_digits = 4;
|
| - 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<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()) {
|
|
|