Changeset 94452 in webkit for trunk/Source/JavaScriptCore/wtf


Ignore:
Timestamp:
Sep 2, 2011, 3:09:34 PM (14 years ago)
Author:
[email protected]
Message:

Incorporate newer, faster dtoa library
https://bugs.webkit.org/show_bug.cgi?id=66346

Patch by Mark Hahnenberg <[email protected]> on 2011-09-02
Reviewed by Oliver Hunt.

Source/JavaScriptCore:

Added new dtoa library at http://code.google.com/p/double-conversion/.
Replaced old call to dtoa. The new library is much faster than the old one.
We still use the old dtoa for some stuff in WebCore as well as the old strtod,
but we can phase these out eventually as well.

(JSC::numberProtoFuncToExponential):
(JSC::numberProtoFuncToFixed):
(JSC::numberProtoFuncToPrecision):

  • runtime/UString.cpp:

(JSC::UString::number):

  • wtf/CMakeLists.txt:
  • wtf/ThreadingPthreads.cpp:

(WTF::initializeThreading):

  • wtf/ThreadingWin.cpp:

(WTF::initializeThreading):

  • wtf/dtoa.cpp:

(WTF::dtoa):

  • wtf/dtoa.h:
  • wtf/dtoa/COPYING: Added.
  • wtf/dtoa/LICENSE: Added.
  • wtf/dtoa/README: Added.
  • wtf/dtoa/bignum-dtoa.cc: Added.
  • wtf/dtoa/bignum-dtoa.h: Added.
  • wtf/dtoa/bignum.cc: Added.
  • wtf/dtoa/bignum.h: Added.

(WTF::double_conversion::Bignum::Times10):
(WTF::double_conversion::Bignum::Equal):
(WTF::double_conversion::Bignum::LessEqual):
(WTF::double_conversion::Bignum::Less):
(WTF::double_conversion::Bignum::PlusEqual):
(WTF::double_conversion::Bignum::PlusLessEqual):
(WTF::double_conversion::Bignum::PlusLess):
(WTF::double_conversion::Bignum::EnsureCapacity):
(WTF::double_conversion::Bignum::BigitLength):

  • wtf/dtoa/cached-powers.cc: Added.
  • wtf/dtoa/cached-powers.h: Added.
  • wtf/dtoa/diy-fp.cc: Added.
  • wtf/dtoa/diy-fp.h: Added.

(WTF::double_conversion::DiyFp::DiyFp):
(WTF::double_conversion::DiyFp::Subtract):
(WTF::double_conversion::DiyFp::Minus):
(WTF::double_conversion::DiyFp::Times):
(WTF::double_conversion::DiyFp::Normalize):
(WTF::double_conversion::DiyFp::f):
(WTF::double_conversion::DiyFp::e):
(WTF::double_conversion::DiyFp::set_f):
(WTF::double_conversion::DiyFp::set_e):

  • wtf/dtoa/double-conversion.cc: Added.
  • wtf/dtoa/double-conversion.h: Added.

(WTF::double_conversion::DoubleToStringConverter::DoubleToStringConverter):
(WTF::double_conversion::StringToDoubleConverter::StringToDoubleConverter):

  • wtf/dtoa/double.h: Added.

(WTF::double_conversion::double_to_uint64):
(WTF::double_conversion::uint64_to_double):
(WTF::double_conversion::Double::Double):
(WTF::double_conversion::Double::AsDiyFp):
(WTF::double_conversion::Double::AsNormalizedDiyFp):
(WTF::double_conversion::Double::AsUint64):
(WTF::double_conversion::Double::NextDouble):
(WTF::double_conversion::Double::Exponent):
(WTF::double_conversion::Double::Significand):
(WTF::double_conversion::Double::IsDenormal):
(WTF::double_conversion::Double::IsSpecial):
(WTF::double_conversion::Double::IsNan):
(WTF::double_conversion::Double::IsInfinite):
(WTF::double_conversion::Double::Sign):
(WTF::double_conversion::Double::UpperBoundary):
(WTF::double_conversion::Double::NormalizedBoundaries):
(WTF::double_conversion::Double::value):
(WTF::double_conversion::Double::SignificandSizeForOrderOfMagnitude):
(WTF::double_conversion::Double::Infinity):
(WTF::double_conversion::Double::NaN):
(WTF::double_conversion::Double::DiyFpToUint64):

  • wtf/dtoa/fast-dtoa.cc: Added.
  • wtf/dtoa/fast-dtoa.h: Added.
  • wtf/dtoa/fixed-dtoa.cc: Added.
  • wtf/dtoa/fixed-dtoa.h: Added.
  • wtf/dtoa/strtod.cc: Added.
  • wtf/dtoa/strtod.h: Added.
  • wtf/dtoa/utils.h: Added.

(WTF::double_conversion::Max):
(WTF::double_conversion::Min):
(WTF::double_conversion::StrLength):
(WTF::double_conversion::Vector::Vector):
(WTF::double_conversion::Vector::SubVector):
(WTF::double_conversion::Vector::length):
(WTF::double_conversion::Vector::is_empty):
(WTF::double_conversion::Vector::start):
(WTF::double_conversion::Vector::operator[]):
(WTF::double_conversion::Vector::first):
(WTF::double_conversion::Vector::last):
(WTF::double_conversion::StringBuilder::StringBuilder):
(WTF::double_conversion::StringBuilder::~StringBuilder):
(WTF::double_conversion::StringBuilder::size):
(WTF::double_conversion::StringBuilder::position):
(WTF::double_conversion::StringBuilder::Reset):
(WTF::double_conversion::StringBuilder::AddCharacter):
(WTF::double_conversion::StringBuilder::AddString):
(WTF::double_conversion::StringBuilder::AddSubstring):
(WTF::double_conversion::StringBuilder::AddPadding):
(WTF::double_conversion::StringBuilder::Finalize):
(WTF::double_conversion::StringBuilder::is_finalized):
(WTF::double_conversion::BitCast):

  • wtf/wtf.pri:

Source/WebCore:

No new tests.

Added new dtoa library at http://code.google.com/p/double-conversion/.
Replaced old call to dtoa. The new library is much faster than the old one.
We still use the old dtoa for some stuff in WebCore as well as the old strtod,
but we can phase these out eventually as well.

  • ForwardingHeaders/wtf/dtoa/double-conversion.h: Added.
  • WebCore.vcproj/copyForwardingHeaders.cmd:
  • css/CSSPrimitiveValue.cpp:

(WebCore::formatNumber):

  • html/parser/HTMLParserIdioms.cpp:

(WebCore::serializeForNumberType):

  • inspector/InspectorValues.cpp:

(WebCore::InspectorBasicValue::writeJSON):

  • platform/graphics/Color.cpp:

(WebCore::Color::serialized):

Location:
trunk/Source/JavaScriptCore/wtf
Files:
22 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wtf/CMakeLists.txt

    r92974 r94452  
    100100    dtoa.h
    101101
     102    dtoa/bignum-dtoa.h
     103    dtoa/bignum.h
     104    dtoa/cached-powers.h
     105    dtoa/diy-fp.h
     106    dtoa/double-conversion.h
     107    dtoa/double.h
     108    dtoa/fast-dtoa.h
     109    dtoa/fixed-dtoa.h
     110    dtoa/strtod.h
     111    dtoa/utils.h
     112
     113    dtoa/bignum-dtoa.h
     114    dtoa/bignum.h
     115    dtoa/cached-powers.h
     116    dtoa/diy-fp.h
     117    dtoa/double-conversion.h
     118    dtoa/double.h
     119    dtoa/fast-dtoa.h
     120    dtoa/fixed-dtoa.h
     121    dtoa/strtod.h
     122    dtoa/utils.h
     123
    102124    text/AtomicString.h
    103125    text/AtomicStringImpl.h
     
    141163    dtoa.cpp
    142164
     165    dtoa/bignum-dtoa.cc
     166    dtoa/bignum.cc
     167    dtoa/cached-powers.cc
     168    dtoa/diy-fp.cc
     169    dtoa/double-conversion.cc
     170    dtoa/fast-dtoa.cc
     171    dtoa/fixed-dtoa.cc
     172    dtoa/strtod.cc
     173
     174    dtoa/bignum-dtoa.cc
     175    dtoa/bignum.cc
     176    dtoa/cached-powers.cc
     177    dtoa/diy-fp.cc
     178    dtoa/double-conversion.cc
     179    dtoa/fast-dtoa.cc
     180    dtoa/fixed-dtoa.cc
     181    dtoa/strtod.cc
     182
    143183    text/AtomicString.cpp
    144184    text/CString.cpp
     
    155195    "${JAVASCRIPTCORE_DIR}/wtf"
    156196    "${JAVASCRIPTCORE_DIR}/wtf/unicode"
     197    "${JAVASCRIPTCORE_DIR}/wtf/dtoa"
    157198    "${JavaScriptCore_INCLUDE_DIRECTORIES}"
    158199)
  • trunk/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp

    r94191 r94452  
    3636#include "DateMath.h"
    3737#include "dtoa.h"
     38#include "dtoa/cached-powers.h"
    3839#include "HashMap.h"
    3940#include "RandomNumberSeed.h"
     
    7475        return;
    7576
     77    WTF::double_conversion::initialize();
    7678    // StringImpl::empty() does not construct its static string in a threadsafe fashion,
    7779    // so ensure it has been initialized from here.
  • trunk/Source/JavaScriptCore/wtf/ThreadingWin.cpp

    r91906 r94452  
    8888#include "DateMath.h"
    8989#include "dtoa.h"
     90#include "dtoa/cached-powers.h"
    9091
    9192#include "MainThread.h"
     
    164165        return;
    165166
     167    WTF::double_conversion::initialize();
    166168    // StringImpl::empty() does not construct its static string in a threadsafe fashion,
    167169    // so ensure it has been initialized from here.
  • trunk/Source/JavaScriptCore/wtf/dtoa.cpp

    r93017 r94452  
    7676#include <wtf/AlwaysInline.h>
    7777#include <wtf/Assertions.h>
    78 #include <wtf/DecimalNumber.h>
    7978#include <wtf/FastMalloc.h>
    8079#include <wtf/MathExtras.h>
     
    8281#include <wtf/UnusedParam.h>
    8382#include <wtf/Vector.h>
     83#include <wtf/dtoa/double-conversion.h>
    8484
    8585#if COMPILER(MSVC)
     
    18031803}
    18041804
    1805 static ALWAYS_INLINE void copyAsciiToUTF16(UChar* next, const char* src, unsigned size)
    1806 {
    1807     for (unsigned i = 0; i < size; ++i)
    1808         *next++ = *src++;
    1809 }
    1810 
    1811 unsigned numberToString(double d, NumberToStringBuffer buffer)
    1812 {
    1813     // Handle NaN and Infinity.
    1814     if (!isfinite(d)) {
    1815         if (isnan(d)) {
    1816             copyAsciiToUTF16(buffer, "NaN", 3);
    1817             return 3;
    1818         }
    1819         if (d > 0) {
    1820             copyAsciiToUTF16(buffer, "Infinity", 8);
    1821             return 8;
    1822         }
    1823         copyAsciiToUTF16(buffer, "-Infinity", 9);
    1824         return 9;
    1825     }
    1826 
    1827     // Convert to decimal with rounding.
    1828     DecimalNumber number(d);
    1829     return number.exponent() >= -6 && number.exponent() < 21
    1830         ? number.toStringDecimal(buffer, NumberToStringBufferLength)
    1831         : number.toStringExponential(buffer, NumberToStringBufferLength);
     1805
     1806const char *numberToString(double d, NumberToStringBuffer buffer)
     1807{
     1808    double_conversion::StringBuilder builder(buffer, NumberToStringBufferLength);
     1809    const double_conversion::DoubleToStringConverter& converter = double_conversion::DoubleToStringConverter::EcmaScriptConverter();
     1810    converter.ToShortest(d, &builder);
     1811    return builder.Finalize();
    18321812}
    18331813
  • trunk/Source/JavaScriptCore/wtf/dtoa.h

    r70198 r94452  
    2222#define WTF_dtoa_h
    2323
     24#include <wtf/dtoa/double-conversion.h>
    2425#include <wtf/unicode/Unicode.h>
    2526
     
    2930extern WTF::Mutex* s_dtoaP5Mutex;
    3031
    31 // s00: input string. Must not be 0 and must be terminated by 0.
    32 // se: *se will have the last consumed character position + 1.
    33 double strtod(const char* s00, char** se);
    34 
    3532typedef char DtoaBuffer[80];
    3633
     
    3936void dtoaRoundDP(DtoaBuffer result, double dd, int ndigits, bool& sign, int& exponent, unsigned& precision);
    4037
     38// s00: input string. Must not be 0 and must be terminated by 0.
     39// se: *se will have the last consumed character position + 1.
     40double strtod(const char* s00, char** se);
     41
    4142// Size = 80 for sizeof(DtoaBuffer) + some sign bits, decimal point, 'e', exponent digits.
    4243const unsigned NumberToStringBufferLength = 96;
    43 typedef UChar NumberToStringBuffer[NumberToStringBufferLength];
    44 unsigned numberToString(double, NumberToStringBuffer);
     44typedef char NumberToStringBuffer[NumberToStringBufferLength];
     45typedef UChar NumberToUStringBuffer[NumberToStringBufferLength];
     46const char *numberToString(double, NumberToStringBuffer);
    4547
    4648} // namespace WTF
    4749
    4850using WTF::NumberToStringBuffer;
     51using WTF::NumberToUStringBuffer;
    4952using WTF::numberToString;
    5053
  • trunk/Source/JavaScriptCore/wtf/wtf.pri

    r94075 r94452  
    77    wtf/CurrentTime.cpp \
    88    wtf/DateMath.cpp \
     9    wtf/DecimalNumber.cpp \
    910    wtf/dtoa.cpp \
    10     wtf/DecimalNumber.cpp \
     11    wtf/dtoa/bignum-dtoa.cc \
     12    wtf/dtoa/bignum.cc \
     13    wtf/dtoa/cached-powers.cc \
     14    wtf/dtoa/diy-fp.cc \
     15    wtf/dtoa/double-conversion.cc \
     16    wtf/dtoa/fast-dtoa.cc \
     17    wtf/dtoa/fixed-dtoa.cc \
     18    wtf/dtoa/strtod.cc \
    1119    wtf/FastMalloc.cpp \
    1220    wtf/gobject/GOwnPtr.cpp \
Note: See TracChangeset for help on using the changeset viewer.