Changeset 127991 in webkit


Ignore:
Timestamp:
Sep 9, 2012 1:48:23 PM (12 years ago)
Author:
Patrick Gansterer
Message:

Make the String initialization on the function side of String::number()
https://bugs.webkit.org/show_bug.cgi?id=95940

Reviewed by Benjamin Poulain.

Source/JavaScriptCore:

Source/WebKit2:

  • win/WebKit2.def:
  • win/WebKit2CFLite.def:

Source/WTF:

Un-Inline String::number() to make the String initialization done on the function side
instead of being on the caller side.

  • GNUmakefile.list.am:
  • WTF.gypi:
  • WTF.pro:
  • WTF.vcproj/WTF.vcproj:
  • WTF.xcodeproj/project.pbxproj:
  • wtf/CMakeLists.txt:
  • wtf/text/IntegerToStringConversion.cpp: Removed.
  • wtf/text/IntegerToStringConversion.h:

(WTF::numberToStringImpl):
(WTF::numberToStringSigned):
(WTF::numberToStringUnsigned):

  • wtf/text/WTFString.cpp:

(WTF::String::number):

  • wtf/text/WTFString.h:

Tools:

  • TestWebKitAPI/Tests/WTF/IntegerToStringConversion.cpp:

(testBoundaries):
(testNumbers):

Location:
trunk
Files:
1 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r127987 r127991  
     12012-09-09  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Make the String initialization on the function side of String::number()
     4        https://bugs.webkit.org/show_bug.cgi?id=95940
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
     9
    1102012-09-09  Geoffrey Garen  <ggaren@apple.com>
    211
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r127351 r127991  
    254254    ?notifyWriteSlow@WatchpointSet@JSC@@QAEXXZ
    255255    ?nullptr@@3Vnullptr_t@std@@A
    256     ?number@String@WTF@@SA?AV12@NII@Z
    257256    ?numberToFixedPrecisionString@WTF@@YAPBDNIQAD_N@Z
    258257    ?numberToFixedWidthString@WTF@@YAPBDNIQAD@Z
    259258    ?numberToString@WTF@@YAPBDNQAD@Z
    260     ?numberToStringImpl@WTF@@YA?AV?$PassRefPtr@VStringImpl@WTF@@@1@_J@Z
    261     ?numberToStringImpl@WTF@@YA?AV?$PassRefPtr@VStringImpl@WTF@@@1@_K@Z
    262     ?numberToStringImpl@WTF@@YA?AV?$PassRefPtr@VStringImpl@WTF@@@1@H@Z
    263     ?numberToStringImpl@WTF@@YA?AV?$PassRefPtr@VStringImpl@WTF@@@1@I@Z
    264     ?numberToStringImpl@WTF@@YA?AV?$PassRefPtr@VStringImpl@WTF@@@1@J@Z
    265     ?numberToStringImpl@WTF@@YA?AV?$PassRefPtr@VStringImpl@WTF@@@1@K@Z
    266259    ?objectAtScope@JSScope@JSC@@SAPAVJSObject@2@PAV12@@Z
    267260    ?objectCount@Heap@JSC@@QAEIXZ
  • trunk/Source/WTF/ChangeLog

    r127973 r127991  
     12012-09-09  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Make the String initialization on the function side of String::number()
     4        https://bugs.webkit.org/show_bug.cgi?id=95940
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        Un-Inline String::number() to make the String initialization done on the function side
     9        instead of being on the caller side.
     10
     11        * GNUmakefile.list.am:
     12        * WTF.gypi:
     13        * WTF.pro:
     14        * WTF.vcproj/WTF.vcproj:
     15        * WTF.xcodeproj/project.pbxproj:
     16        * wtf/CMakeLists.txt:
     17        * wtf/text/IntegerToStringConversion.cpp: Removed.
     18        * wtf/text/IntegerToStringConversion.h:
     19        (WTF::numberToStringImpl):
     20        (WTF::numberToStringSigned):
     21        (WTF::numberToStringUnsigned):
     22        * wtf/text/WTFString.cpp:
     23        (WTF::String::number):
     24        * wtf/text/WTFString.h:
     25
    1262012-09-08  Andreas Kling  <kling@webkit.org>
    227
  • trunk/Source/WTF/GNUmakefile.list.am

    r126658 r127991  
    209209    Source/WTF/wtf/text/CString.cpp \
    210210    Source/WTF/wtf/text/CString.h \
    211     Source/WTF/wtf/text/IntegerToStringConversion.cpp \
    212211    Source/WTF/wtf/text/IntegerToStringConversion.h \
    213212    Source/WTF/wtf/text/StringBuffer.h \
  • trunk/Source/WTF/WTF.gypi

    r126658 r127991  
    225225            'wtf/text/Base64.cpp',
    226226            'wtf/text/CString.cpp',
    227             'wtf/text/IntegerToStringConversion.cpp',
    228227            'wtf/text/StringBuilder.cpp',
    229228            'wtf/text/StringImpl.cpp',
  • trunk/Source/WTF/WTF.pro

    r126658 r127991  
    220220    text/Base64.cpp \
    221221    text/CString.cpp \
    222     text/IntegerToStringConversion.cpp \
    223222    text/StringBuilder.cpp \
    224223    text/StringImpl.cpp \
  • trunk/Source/WTF/WTF.vcproj/WTF.vcproj

    r126658 r127991  
    425425                        </File>
    426426                        <File
    427                                 RelativePath="..\wtf\text\IntegerToStringConversion.cpp"
    428                                 >
    429                         </File>
    430                         <File
    431427                                RelativePath="..\wtf\text\IntegerToStringConversion.h"
    432428                                >
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r126658 r127991  
    1212                143F61201565F0F900DB514A /* RAMSize.h in Headers */ = {isa = PBXBuildFile; fileRef = 143F611E1565F0F900DB514A /* RAMSize.h */; settings = {ATTRIBUTES = (Private, ); }; };
    1313                14F3B0F715E45E4600210069 /* SaturatedArithmetic.h in Headers */ = {isa = PBXBuildFile; fileRef = 14F3B0F615E45E4600210069 /* SaturatedArithmetic.h */; settings = {ATTRIBUTES = (Private, ); }; };
    14                 26147B0915DDCCDC00DDB907 /* IntegerToStringConversion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26147B0715DDCCDC00DDB907 /* IntegerToStringConversion.cpp */; };
    1514                26147B0A15DDCCDC00DDB907 /* IntegerToStringConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */; };
    1615                2C05385415BC819000F21B96 /* GregorianDateTime.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C05385315BC819000F21B96 /* GregorianDateTime.h */; };
     
    259258                143F611E1565F0F900DB514A /* RAMSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAMSize.h; sourceTree = "<group>"; };
    260259                14F3B0F615E45E4600210069 /* SaturatedArithmetic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SaturatedArithmetic.h; sourceTree = "<group>"; };
    261                 26147B0715DDCCDC00DDB907 /* IntegerToStringConversion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntegerToStringConversion.cpp; sourceTree = "<group>"; };
    262260                26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntegerToStringConversion.h; sourceTree = "<group>"; };
    263261                2C05385315BC819000F21B96 /* GregorianDateTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GregorianDateTime.h; sourceTree = "<group>"; };
     
    796794                                A8A47321151A825B004123FF /* CString.cpp */,
    797795                                A8A47322151A825B004123FF /* CString.h */,
    798                                 26147B0715DDCCDC00DDB907 /* IntegerToStringConversion.cpp */,
    799796                                26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */,
    800797                                A8A47323151A825B004123FF /* StringBuffer.h */,
     
    11891186                                2CCD892A15C0390200285083 /* GregorianDateTime.cpp in Sources */,
    11901187                                A8A473D8151A825B004123FF /* HashTable.cpp in Sources */,
    1191                                 26147B0915DDCCDC00DDB907 /* IntegerToStringConversion.cpp in Sources */,
    11921188                                A8A473E5151A825B004123FF /* MainThread.cpp in Sources */,
    11931189                                A8A473E4151A825B004123FF /* MainThreadMac.mm in Sources */,
  • trunk/Source/WTF/wtf/CMakeLists.txt

    r126658 r127991  
    184184    text/Base64.cpp
    185185    text/CString.cpp
    186     text/IntegerToStringConversion.cpp
    187186    text/StringBuilder.cpp
    188187    text/StringImpl.cpp
  • trunk/Source/WTF/wtf/text/IntegerToStringConversion.h

    r127761 r127991  
    11/*
    22 * Copyright (C) 2012 Apple Inc. All Rights Reserved.
     3 * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com>
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    2223#define IntegerToStringConversion_h
    2324
    24 #include "StringImpl.h"
     25#include <wtf/text/StringBuilder.h>
     26#include <wtf/text/StringImpl.h>
    2527
    2628namespace WTF {
    2729
    28 WTF_EXPORT_PRIVATE PassRefPtr<StringImpl> numberToStringImpl(int);
    29 WTF_EXPORT_PRIVATE PassRefPtr<StringImpl> numberToStringImpl(long);
    30 WTF_EXPORT_PRIVATE PassRefPtr<StringImpl> numberToStringImpl(long long);
     30enum PositiveOrNegativeNumber {
     31    PositiveNumber,
     32    NegativeNumber
     33};
    3134
    32 WTF_EXPORT_PRIVATE PassRefPtr<StringImpl> numberToStringImpl(unsigned);
    33 WTF_EXPORT_PRIVATE PassRefPtr<StringImpl> numberToStringImpl(unsigned long);
    34 WTF_EXPORT_PRIVATE PassRefPtr<StringImpl> numberToStringImpl(unsigned long long);
     35template<typename T> struct ConversionTrait;
     36
     37template<> struct ConversionTrait<String> {
     38    typedef PassRefPtr<StringImpl> ReturnType;
     39    typedef void AdditionalArgumentType;
     40    static inline ReturnType flush(LChar* characters, unsigned length, void*) { return StringImpl::create(characters, length); }
     41};
     42template<> struct ConversionTrait<StringBuilder> {
     43    typedef void ReturnType;
     44    typedef StringBuilder AdditionalArgumentType;
     45    static inline ReturnType flush(LChar* characters, unsigned length, StringBuilder* stringBuilder) { stringBuilder->append(characters, length); }
     46};
     47
     48template<typename T> struct UnsignedIntegerTrait;
     49
     50template<> struct UnsignedIntegerTrait<int> {
     51    typedef unsigned int Type;
     52};
     53template<> struct UnsignedIntegerTrait<long> {
     54    typedef unsigned long Type;
     55};
     56template<> struct UnsignedIntegerTrait<long long> {
     57    typedef unsigned long long Type;
     58};
     59
     60template<typename T, typename UnsignedIntegerType, PositiveOrNegativeNumber NumberType>
     61static typename ConversionTrait<T>::ReturnType numberToStringImpl(UnsignedIntegerType number, typename ConversionTrait<T>::AdditionalArgumentType* additionalArgument)
     62{
     63    LChar buf[sizeof(UnsignedIntegerType) * 3 + 1];
     64    LChar* end = buf + WTF_ARRAY_LENGTH(buf);
     65    LChar* p = end;
     66
     67    do {
     68        *--p = static_cast<LChar>((number % 10) + '0');
     69        number /= 10;
     70    } while (number);
     71
     72    if (NumberType == NegativeNumber)
     73        *--p = '-';
     74
     75    return ConversionTrait<T>::flush(p, static_cast<unsigned>(end - p), additionalArgument);
     76}
     77
     78template<typename T, typename SignedIntegerType>
     79inline typename ConversionTrait<T>::ReturnType numberToStringSigned(SignedIntegerType number, typename ConversionTrait<T>::AdditionalArgumentType* additionalArgument = 0)
     80{
     81    if (number < 0)
     82        return numberToStringImpl<T, typename UnsignedIntegerTrait<SignedIntegerType>::Type, NegativeNumber>(-number, additionalArgument);
     83    return numberToStringImpl<T, typename UnsignedIntegerTrait<SignedIntegerType>::Type, PositiveNumber>(number, additionalArgument);
     84}
     85
     86template<typename T, typename UnsignedIntegerType>
     87inline typename ConversionTrait<T>::ReturnType numberToStringUnsigned(UnsignedIntegerType number, typename ConversionTrait<T>::AdditionalArgumentType* additionalArgument = 0)
     88{
     89    return numberToStringImpl<T, UnsignedIntegerType, PositiveNumber>(number, additionalArgument);
     90}
    3591
    3692} // namespace WTF
  • trunk/Source/WTF/wtf/text/WTFString.cpp

    r127093 r127991  
    418418#endif
    419419}
    420    
     420
     421String String::number(int number)
     422{
     423    return numberToStringSigned<String>(number);
     424}
     425
     426String String::number(unsigned int number)
     427{
     428    return numberToStringUnsigned<String>(number);
     429}
     430
     431String String::number(long number)
     432{
     433    return numberToStringSigned<String>(number);
     434}
     435
     436String String::number(unsigned long number)
     437{
     438    return numberToStringUnsigned<String>(number);
     439}
     440
     441String String::number(long long number)
     442{
     443    return numberToStringSigned<String>(number);
     444}
     445
     446String String::number(unsigned long long number)
     447{
     448    return numberToStringUnsigned<String>(number);
     449}
     450
    421451String String::number(double number, unsigned flags, unsigned precision)
    422452{
  • trunk/Source/WTF/wtf/text/WTFString.h

    r127702 r127991  
    2727
    2828#include <wtf/text/ASCIIFastPath.h>
    29 #include <wtf/text/IntegerToStringConversion.h>
    3029#include <wtf/text/StringImpl.h>
    3130
     
    227226    }
    228227
    229     static String number(unsigned short number) { return numberToStringImpl(number); }
    230     static String number(int number) { return numberToStringImpl(number); }
    231     static String number(unsigned number) { return numberToStringImpl(number); }
    232     static String number(long number) { return numberToStringImpl(number); }
    233     static String number(unsigned long number) { return numberToStringImpl(number); }
    234     static String number(long long number) { return numberToStringImpl(number); }
    235     static String number(unsigned long long number) { return numberToStringImpl(number); }
     228    WTF_EXPORT_STRING_API static String number(int);
     229    WTF_EXPORT_STRING_API static String number(unsigned int);
     230    WTF_EXPORT_STRING_API static String number(long);
     231    WTF_EXPORT_STRING_API static String number(unsigned long);
     232    WTF_EXPORT_STRING_API static String number(long long);
     233    WTF_EXPORT_STRING_API static String number(unsigned long long);
    236234
    237235    WTF_EXPORT_STRING_API static String number(double, unsigned = ShouldRoundSignificantFigures | ShouldTruncateTrailingZeros, unsigned precision = 6);
  • trunk/Source/WebKit2/ChangeLog

    r127988 r127991  
     12012-09-09  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Make the String initialization on the function side of String::number()
     4        https://bugs.webkit.org/show_bug.cgi?id=95940
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * win/WebKit2.def:
     9        * win/WebKit2CFLite.def:
     10
    1112012-09-09  Pierre Rossi  <pierre.rossi@gmail.com>
    212
  • trunk/Source/WebKit2/win/WebKit2.def

    r127876 r127991  
    196196        ?next@ComposedShadowTreeWalker@WebCore@@QAEXXZ
    197197        ?previous@ComposedShadowTreeWalker@WebCore@@QAEXXZ
    198         ?numberToStringImpl@WTF@@YA?AV?$PassRefPtr@VStringImpl@WTF@@@1@H@Z
    199         ?numberToStringImpl@WTF@@YA?AV?$PassRefPtr@VStringImpl@WTF@@@1@I@Z
     198        ?number@String@WTF@@SA?AV12@_K@Z
     199        ?number@String@WTF@@SA?AV12@H@Z
     200        ?number@String@WTF@@SA?AV12@I@Z
     201        ?number@String@WTF@@SA?AV12@NII@Z
    200202        ?overrideUserPreferredLanguages@WebCore@@YAXABV?$Vector@VString@WTF@@$0A@@WTF@@@Z
    201203        ?numberOfScopedHTMLStyleChildren@Node@WebCore@@QBEIXZ
  • trunk/Source/WebKit2/win/WebKit2CFLite.def

    r127876 r127991  
    193193        ?next@ComposedShadowTreeWalker@WebCore@@QAEXXZ
    194194        ?previous@ComposedShadowTreeWalker@WebCore@@QAEXXZ
     195        ?number@String@WTF@@SA?AV12@_K@Z
     196        ?number@String@WTF@@SA?AV12@H@Z
    195197        ?number@String@WTF@@SA?AV12@I@Z
    196         ?number@String@WTF@@SA?AV12@H@Z
     198        ?number@String@WTF@@SA?AV12@NII@Z
    197199        ?overrideUserPreferredLanguages@WebCore@@YAXABV?$Vector@VString@WTF@@$0A@@WTF@@@Z
    198200        ?numberOfScopedHTMLStyleChildren@Node@WebCore@@QBEIXZ
  • trunk/Tools/ChangeLog

    r127988 r127991  
     12012-09-09  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Make the String initialization on the function side of String::number()
     4        https://bugs.webkit.org/show_bug.cgi?id=95940
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * TestWebKitAPI/Tests/WTF/IntegerToStringConversion.cpp:
     9        (testBoundaries):
     10        (testNumbers):
     11
    1122012-09-09  Pierre Rossi  <pierre.rossi@gmail.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WTF/IntegerToStringConversion.cpp

    r126658 r127991  
    2929#include <wtf/StringExtras.h>
    3030#include <wtf/text/CString.h>
    31 #include <wtf/text/IntegerToStringConversion.h>
    3231#include <wtf/text/WTFString.h>
    3332
     
    7675
    7776    const IntegerType min = std::numeric_limits<IntegerType>::min();
    78     CString minStringData = String(WTF::numberToStringImpl(min)).latin1();
     77    CString minStringData = String::number(min).latin1();
    7978    snprintf(buffer.data(), bufferSize, PrintfFormatTrait<IntegerType>::format, min);
    8079    ASSERT_STREQ(buffer.data(), minStringData.data());
    8180
    8281    const IntegerType max = std::numeric_limits<IntegerType>::max();
    83     CString maxStringData = String(WTF::numberToStringImpl(max)).latin1();
     82    CString maxStringData = String::number(max).latin1();
    8483    snprintf(buffer.data(), bufferSize, PrintfFormatTrait<IntegerType>::format, max);
    8584    ASSERT_STREQ(buffer.data(), maxStringData.data());
     
    9594    for (int i = -100; i < 100; ++i) {
    9695        const IntegerType number = static_cast<IntegerType>(i);
    97         CString numberStringData = String(WTF::numberToStringImpl(number)).latin1();
     96        CString numberStringData = String::number(number).latin1();
    9897        snprintf(buffer.data(), bufferSize, PrintfFormatTrait<IntegerType>::format, number);
    9998        ASSERT_STREQ(buffer.data(), numberStringData.data());
Note: See TracChangeset for help on using the changeset viewer.