Reviewers: Lasse Reichstein, Vyacheslav Egorov,

Description:
Reduce the number of global constructor calls by changing a constant to a
(constant) inline function.

This brings down the size of v8's .ctors section to 1/4, hopefully fixing the
recent issues with Chromes' CL 91522.

Please review this at http://codereview.chromium.org/7321005/

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/conversions-inl.h
  M     src/conversions.h


Index: src/conversions-inl.h
===================================================================
--- src/conversions-inl.h       (revision 8559)
+++ src/conversions-inl.h       (working copy)
@@ -151,7 +151,7 @@
           !AdvanceToNonspace(unicode_cache, &current, end)) {
         break;
       } else {
-        return JUNK_STRING_VALUE;
+        return JunkStringValue();
       }
     }

@@ -181,7 +181,7 @@

       if (!allow_trailing_junk &&
           AdvanceToNonspace(unicode_cache, &current, end)) {
-        return JUNK_STRING_VALUE;
+        return JunkStringValue();
       }

       int middle_value = (1 << (overflow_bits_count - 1));
@@ -229,7 +229,7 @@
                                   EndMark end,
                                   int radix) {
   const bool allow_trailing_junk = true;
-  const double empty_string_val = JUNK_STRING_VALUE;
+  const double empty_string_val = JunkStringValue();

   if (!AdvanceToNonspace(unicode_cache, &current, end)) {
     return empty_string_val;
@@ -242,12 +242,12 @@
     // Ignore leading sign; skip following spaces.
     ++current;
     if (current == end) {
-      return JUNK_STRING_VALUE;
+      return JunkStringValue();
     }
   } else if (*current == '-') {
     ++current;
     if (current == end) {
-      return JUNK_STRING_VALUE;
+      return JunkStringValue();
     }
     negative = true;
   }
@@ -260,7 +260,7 @@
       if (*current == 'x' || *current == 'X') {
         radix = 16;
         ++current;
-        if (current == end) return JUNK_STRING_VALUE;
+        if (current == end) return JunkStringValue();
       } else {
         radix = 8;
         leading_zero = true;
@@ -275,14 +275,14 @@
       if (current == end) return SignedZero(negative);
       if (*current == 'x' || *current == 'X') {
         ++current;
-        if (current == end) return JUNK_STRING_VALUE;
+        if (current == end) return JunkStringValue();
       } else {
         leading_zero = true;
       }
     }
   }

-  if (radix < 2 || radix > 36) return JUNK_STRING_VALUE;
+  if (radix < 2 || radix > 36) return JunkStringValue();

   // Skip leading zeros.
   while (*current == '0') {
@@ -292,7 +292,7 @@
   }

   if (!leading_zero && !isDigit(*current, radix)) {
-    return JUNK_STRING_VALUE;
+    return JunkStringValue();
   }

   if (IsPowerOf2(radix)) {
@@ -340,7 +340,7 @@

     if (!allow_trailing_junk &&
         AdvanceToNonspace(unicode_cache, &current, end)) {
-      return JUNK_STRING_VALUE;
+      return JunkStringValue();
     }

     ASSERT(buffer_pos < kBufferSize);
@@ -406,7 +406,7 @@

   if (!allow_trailing_junk &&
       AdvanceToNonspace(unicode_cache, &current, end)) {
-    return JUNK_STRING_VALUE;
+    return JunkStringValue();
   }

   return negative ? -v : v;
@@ -456,22 +456,22 @@
   if (*current == '+') {
     // Ignore leading sign.
     ++current;
-    if (current == end) return JUNK_STRING_VALUE;
+    if (current == end) return JunkStringValue();
   } else if (*current == '-') {
     ++current;
-    if (current == end) return JUNK_STRING_VALUE;
+    if (current == end) return JunkStringValue();
     negative = true;
   }

   static const char kInfinitySymbol[] = "Infinity";
   if (*current == kInfinitySymbol[0]) {
     if (!SubStringEquals(&current, end, kInfinitySymbol)) {
-      return JUNK_STRING_VALUE;
+      return JunkStringValue();
     }

     if (!allow_trailing_junk &&
         AdvanceToNonspace(unicode_cache, &current, end)) {
-      return JUNK_STRING_VALUE;
+      return JunkStringValue();
     }

     ASSERT(buffer_pos == 0);
@@ -489,7 +489,7 @@
     if ((flags & ALLOW_HEX) && (*current == 'x' || *current == 'X')) {
       ++current;
       if (current == end || !isDigit(*current, 16)) {
-        return JUNK_STRING_VALUE;  // "0x".
+        return JunkStringValue();  // "0x".
       }

       return InternalStringToIntDouble<4>(unicode_cache,
@@ -529,13 +529,13 @@
   }

   if (*current == '.') {
-    if (octal && !allow_trailing_junk) return JUNK_STRING_VALUE;
+    if (octal && !allow_trailing_junk) return JunkStringValue();
     if (octal) goto parsing_done;

     ++current;
     if (current == end) {
       if (significant_digits == 0 && !leading_zero) {
-        return JUNK_STRING_VALUE;
+        return JunkStringValue();
       } else {
         goto parsing_done;
       }
@@ -576,18 +576,18 @@
     // If exponent < 0 then string was [+-]\.0*...
     // If significant_digits != 0 the string is not equal to 0.
     // Otherwise there are no digits in the string.
-    return JUNK_STRING_VALUE;
+    return JunkStringValue();
   }

   // Parse exponential part.
   if (*current == 'e' || *current == 'E') {
-    if (octal) return JUNK_STRING_VALUE;
+    if (octal) return JunkStringValue();
     ++current;
     if (current == end) {
       if (allow_trailing_junk) {
         goto parsing_done;
       } else {
-        return JUNK_STRING_VALUE;
+        return JunkStringValue();
       }
     }
     char sign = '+';
@@ -598,7 +598,7 @@
         if (allow_trailing_junk) {
           goto parsing_done;
         } else {
-          return JUNK_STRING_VALUE;
+          return JunkStringValue();
         }
       }
     }
@@ -607,7 +607,7 @@
       if (allow_trailing_junk) {
         goto parsing_done;
       } else {
-        return JUNK_STRING_VALUE;
+        return JunkStringValue();
       }
     }

@@ -631,7 +631,7 @@

   if (!allow_trailing_junk &&
       AdvanceToNonspace(unicode_cache, &current, end)) {
-    return JUNK_STRING_VALUE;
+    return JunkStringValue();
   }

   parsing_done:
Index: src/conversions.h
===================================================================
--- src/conversions.h   (revision 8559)
+++ src/conversions.h   (working copy)
@@ -44,9 +44,12 @@
 // we don't need to preserve all the digits.
 const int kMaxSignificantDigits = 772;

-static const double JUNK_STRING_VALUE =
-    std::numeric_limits<double>::quiet_NaN();

+static double JunkStringValue() {
+  return std::numeric_limits<double>::quiet_NaN();
+}
+
+
 static bool isDigit(int x, int radix) {
   return (x >= '0' && x <= '9' && x < '0' + radix)
       || (radix > 10 && x >= 'a' && x < 'a' + radix - 10)


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to