Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: src/conversions.cc

Issue 1367004: Optimization for parsing integers of limited length (in digits). (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/parse-int-float.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/conversions.cc
===================================================================
--- src/conversions.cc (revision 4297)
+++ src/conversions.cc (working copy)
@@ -377,6 +377,7 @@
int significant_digits = 0;
int insignificant_digits = 0;
bool nonzero_digit_dropped = false;
+ bool fractional_part = false;
double signed_zero = 0.0;
@@ -454,8 +455,6 @@
}
if (*current == '.') {
- ASSERT(buffer_pos < kBufferSize);
- buffer[buffer_pos++] = '.';
++current;
if (current == end) {
if (significant_digits == 0 && !leading_zero) {
@@ -476,6 +475,10 @@
}
}
+ ASSERT(buffer_pos < kBufferSize);
+ buffer[buffer_pos++] = '.';
+ fractional_part = true;
+
// There is the fractional part.
while (*current >= '0' && *current <= '9') {
if (significant_digits < kMaxSignificantDigits) {
@@ -580,6 +583,11 @@
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';
@@ -597,6 +605,16 @@
}
ASSERT(exponent == 0);
buffer_pos += exp_digits;
+ } else if (!fractional_part && significant_digits <= kMaxDigitsInInt) {
+ if (significant_digits == 0) return signed_zero;
+ 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);
}
ASSERT(buffer_pos < kBufferSize);
« no previous file with comments | « no previous file | test/mjsunit/parse-int-float.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698