summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/runtime/NumericStrings.h
diff options
context:
space:
mode:
Diffstat (limited to 'JavaScriptCore/runtime/NumericStrings.h')
-rw-r--r--JavaScriptCore/runtime/NumericStrings.h32
1 files changed, 28 insertions, 4 deletions
diff --git a/JavaScriptCore/runtime/NumericStrings.h b/JavaScriptCore/runtime/NumericStrings.h
index c0696a4..d65f142 100644
--- a/JavaScriptCore/runtime/NumericStrings.h
+++ b/JavaScriptCore/runtime/NumericStrings.h
@@ -27,6 +27,7 @@
#define NumericStrings_h
#include "UString.h"
+#include <wtf/FixedArray.h>
#include <wtf/HashFunctions.h>
namespace JSC {
@@ -39,20 +40,33 @@ namespace JSC {
if (d == entry.key && !entry.value.isNull())
return entry.value;
entry.key = d;
- entry.value = UString::from(d);
+ entry.value = UString::number(d);
return entry.value;
}
UString add(int i)
{
+ if (static_cast<unsigned>(i) < cacheSize)
+ return lookupSmallString(static_cast<unsigned>(i));
CacheEntry<int>& entry = lookup(i);
if (i == entry.key && !entry.value.isNull())
return entry.value;
entry.key = i;
- entry.value = UString::from(i);
+ entry.value = UString::number(i);
return entry.value;
}
+ UString add(unsigned i)
+ {
+ if (i < cacheSize)
+ return lookupSmallString(static_cast<unsigned>(i));
+ CacheEntry<unsigned>& entry = lookup(i);
+ if (i == entry.key && !entry.value.isNull())
+ return entry.value;
+ entry.key = i;
+ entry.value = UString::number(i);
+ return entry.value;
+ }
private:
static const size_t cacheSize = 64;
@@ -64,9 +78,19 @@ namespace JSC {
CacheEntry<double>& lookup(double d) { return doubleCache[WTF::FloatHash<double>::hash(d) & (cacheSize - 1)]; }
CacheEntry<int>& lookup(int i) { return intCache[WTF::IntHash<int>::hash(i) & (cacheSize - 1)]; }
+ CacheEntry<unsigned>& lookup(unsigned i) { return unsignedCache[WTF::IntHash<unsigned>::hash(i) & (cacheSize - 1)]; }
+ const UString& lookupSmallString(unsigned i)
+ {
+ ASSERT(i < cacheSize);
+ if (smallIntCache[i].isNull())
+ smallIntCache[i] = UString::number(i);
+ return smallIntCache[i];
+ }
- CacheEntry<double> doubleCache[cacheSize];
- CacheEntry<int> intCache[cacheSize];
+ FixedArray<CacheEntry<double>, cacheSize> doubleCache;
+ FixedArray<CacheEntry<int>, cacheSize> intCache;
+ FixedArray<CacheEntry<unsigned>, cacheSize> unsignedCache;
+ FixedArray<UString, cacheSize> smallIntCache;
};
} // namespace JSC