Changeset 47622 in webkit for trunk/JavaScriptCore/runtime/NumericStrings.h
- Timestamp:
- Aug 20, 2009, 10:41:54 PM (16 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/NumericStrings.h
r47617 r47622 1 1 /* 2 * Copyright (C) 200 8Apple Inc. All Rights Reserved.2 * Copyright (C) 2009 Apple Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #ifndef SmallStrings_h27 #define SmallStrings_h26 #ifndef NumericStrings_h 27 #define NumericStrings_h 28 28 29 29 #include "UString.h" 30 #include <wtf/ OwnPtr.h>30 #include <wtf/HashFunctions.h> 31 31 32 32 namespace JSC { 33 33 34 class JSGlobalData; 35 class JSString; 36 37 class SmallStringsStorage; 38 39 class SmallStrings : public Noncopyable { 34 class NumericStrings { 40 35 public: 41 SmallStrings(); 42 ~SmallStrings(); 43 44 JSString* emptyString(JSGlobalData* globalData) 36 UString add(double d) 45 37 { 46 if (!m_emptyString) 47 createEmptyString(globalData); 48 return m_emptyString; 49 } 50 JSString* singleCharacterString(JSGlobalData* globalData, unsigned char character) 51 { 52 if (!m_singleCharacterStrings[character]) 53 createSingleCharacterString(globalData, character); 54 return m_singleCharacterStrings[character]; 38 CacheEntry<double>& entry = lookup(d); 39 if (d == entry.key && !entry.value.isNull()) 40 return entry.value; 41 entry.key = d; 42 entry.value = UString::from(d); 43 return entry.value; 55 44 } 56 45 57 UString::Rep* singleCharacterStringRep(unsigned char character); 58 59 void mark(); 60 61 unsigned count() const; 46 UString add(int i) 47 { 48 CacheEntry<int>& entry = lookup(i); 49 if (i == entry.key && !entry.value.isNull()) 50 return entry.value; 51 entry.key = i; 52 entry.value = UString::from(i); 53 return entry.value; 54 } 62 55 63 56 private: 64 void createEmptyString(JSGlobalData*); 65 void createSingleCharacterString(JSGlobalData*, unsigned char); 57 static const size_t cacheSize = 64; 66 58 67 JSString* m_emptyString; 68 JSString* m_singleCharacterStrings[0x100]; 69 OwnPtr<SmallStringsStorage> m_storage; 59 template<typename T> 60 struct CacheEntry { 61 T key; 62 UString value; 63 }; 64 65 CacheEntry<double>& lookup(double d) { return doubleCache[WTF::FloatHash<double>::hash(d) & (cacheSize - 1)]; } 66 CacheEntry<int>& lookup(int i) { return intCache[WTF::IntHash<int>::hash(i) & (cacheSize - 1)]; } 67 68 CacheEntry<double> doubleCache[cacheSize]; 69 CacheEntry<int> intCache[cacheSize]; 70 70 }; 71 71 72 72 } // namespace JSC 73 73 74 #endif // SmallStrings_h74 #endif // NumericStrings_h
Note:
See TracChangeset
for help on using the changeset viewer.