From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/JavaScriptCore/runtime/NumericStrings.h | 109 ++++++++++++------------- 1 file changed, 53 insertions(+), 56 deletions(-) (limited to 'Source/JavaScriptCore/runtime/NumericStrings.h') diff --git a/Source/JavaScriptCore/runtime/NumericStrings.h b/Source/JavaScriptCore/runtime/NumericStrings.h index 3bb5b91c8..86c5c3823 100644 --- a/Source/JavaScriptCore/runtime/NumericStrings.h +++ b/Source/JavaScriptCore/runtime/NumericStrings.h @@ -23,8 +23,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef NumericStrings_h -#define NumericStrings_h +#pragma once #include #include @@ -32,67 +31,65 @@ namespace JSC { - class NumericStrings { - public: - ALWAYS_INLINE String add(double d) - { - CacheEntry& entry = lookup(d); - if (d == entry.key && !entry.value.isNull()) - return entry.value; - entry.key = d; - entry.value = String::numberToStringECMAScript(d); +class NumericStrings { +public: + ALWAYS_INLINE const String& add(double d) + { + CacheEntry& entry = lookup(d); + if (d == entry.key && !entry.value.isNull()) return entry.value; - } + entry.key = d; + entry.value = String::numberToStringECMAScript(d); + return entry.value; + } - ALWAYS_INLINE String add(int i) - { - if (static_cast(i) < cacheSize) - return lookupSmallString(static_cast(i)); - CacheEntry& entry = lookup(i); - if (i == entry.key && !entry.value.isNull()) - return entry.value; - entry.key = i; - entry.value = String::number(i); + ALWAYS_INLINE const String& add(int i) + { + if (static_cast(i) < cacheSize) + return lookupSmallString(static_cast(i)); + CacheEntry& entry = lookup(i); + if (i == entry.key && !entry.value.isNull()) return entry.value; - } + entry.key = i; + entry.value = String::number(i); + return entry.value; + } - ALWAYS_INLINE String add(unsigned i) - { - if (i < cacheSize) - return lookupSmallString(static_cast(i)); - CacheEntry& entry = lookup(i); - if (i == entry.key && !entry.value.isNull()) - return entry.value; - entry.key = i; - entry.value = String::number(i); + ALWAYS_INLINE const String& add(unsigned i) + { + if (i < cacheSize) + return lookupSmallString(static_cast(i)); + CacheEntry& entry = lookup(i); + if (i == entry.key && !entry.value.isNull()) return entry.value; - } - private: - static const size_t cacheSize = 64; + entry.key = i; + entry.value = String::number(i); + return entry.value; + } +private: + static const size_t cacheSize = 64; - template - struct CacheEntry { - T key; - String value; - }; + template + struct CacheEntry { + T key; + String value; + }; - CacheEntry& lookup(double d) { return doubleCache[WTF::FloatHash::hash(d) & (cacheSize - 1)]; } - CacheEntry& lookup(int i) { return intCache[WTF::IntHash::hash(i) & (cacheSize - 1)]; } - CacheEntry& lookup(unsigned i) { return unsignedCache[WTF::IntHash::hash(i) & (cacheSize - 1)]; } - ALWAYS_INLINE const String& lookupSmallString(unsigned i) - { - ASSERT(i < cacheSize); - if (smallIntCache[i].isNull()) - smallIntCache[i] = String::number(i); - return smallIntCache[i]; - } + CacheEntry& lookup(double d) { return doubleCache[WTF::FloatHash::hash(d) & (cacheSize - 1)]; } + CacheEntry& lookup(int i) { return intCache[WTF::IntHash::hash(i) & (cacheSize - 1)]; } + CacheEntry& lookup(unsigned i) { return unsignedCache[WTF::IntHash::hash(i) & (cacheSize - 1)]; } + ALWAYS_INLINE const String& lookupSmallString(unsigned i) + { + ASSERT(i < cacheSize); + if (smallIntCache[i].isNull()) + smallIntCache[i] = String::number(i); + return smallIntCache[i]; + } - std::array, cacheSize> doubleCache; - std::array, cacheSize> intCache; - std::array, cacheSize> unsignedCache; - std::array smallIntCache; - }; + std::array, cacheSize> doubleCache; + std::array, cacheSize> intCache; + std::array, cacheSize> unsignedCache; + std::array smallIntCache; +}; } // namespace JSC - -#endif // NumericStrings_h -- cgit v1.2.1