Changeset 47622 in webkit for trunk/JavaScriptCore/runtime
- Timestamp:
- Aug 20, 2009, 10:41:54 PM (16 years ago)
- Location:
- trunk/JavaScriptCore/runtime
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSCell.h
r47288 r47622 316 316 } 317 317 318 inline UString JSValue::toString(ExecState* exec) const319 {320 if (isCell())321 return asCell()->toString(exec);322 if (isInt32())323 return UString::from(asInt32());324 if (isDouble())325 return asDouble() == 0.0 ? "0" : UString::from(asDouble());326 if (isTrue())327 return "true";328 if (isFalse())329 return "false";330 if (isNull())331 return "null";332 ASSERT(isUndefined());333 return "undefined";334 }335 336 318 inline bool JSValue::needsThisConversion() const 337 319 { -
trunk/JavaScriptCore/runtime/JSGlobalData.h
r47412 r47622 35 35 #include "JSValue.h" 36 36 #include "MarkStack.h" 37 #include "NumericStrings.h" 37 38 #include "SmallStrings.h" 38 39 #include "TimeoutChecker.h" … … 115 116 const MarkedArgumentBuffer* emptyList; // Lists are supposed to be allocated on the stack to have their elements properly marked, which is not the case here - but this list has nothing to mark. 116 117 SmallStrings smallStrings; 118 NumericStrings numericStrings; 117 119 118 120 #if ENABLE(ASSEMBLER) -
trunk/JavaScriptCore/runtime/JSNumberCell.cpp
r46598 r47622 55 55 UString JSNumberCell::toString(ExecState*) const 56 56 { 57 if (m_value == 0.0) // +0.0 or -0.058 return "0";59 57 return UString::from(m_value); 60 58 } … … 62 60 UString JSNumberCell::toThisString(ExecState*) const 63 61 { 64 if (m_value == 0.0) // +0.0 or -0.065 return "0";66 62 return UString::from(m_value); 67 63 } -
trunk/JavaScriptCore/runtime/JSString.h
r47267 r47622 212 212 } 213 213 214 inline UString JSValue::toString(ExecState* exec) const 215 { 216 if (isString()) 217 return static_cast<JSString*>(asCell())->value(); 218 if (isInt32()) 219 return exec->globalData().numericStrings.add(asInt32()); 220 if (isDouble()) 221 return exec->globalData().numericStrings.add(asDouble()); 222 if (isTrue()) 223 return "true"; 224 if (isFalse()) 225 return "false"; 226 if (isNull()) 227 return "null"; 228 if (isUndefined()) 229 return "undefined"; 230 ASSERT(isCell()); 231 return asCell()->toString(exec); 232 } 233 214 234 } // namespace JSC 215 235 -
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 -
trunk/JavaScriptCore/runtime/Operations.h
r46598 r47622 309 309 UString result(resultRep); 310 310 311 // Loop over the ope nards, writing them into the output buffer.311 // Loop over the operands, writing them into the output buffer. 312 312 for (unsigned i = 0; i < count; ++i) { 313 313 JSValue v = strings[i].jsValue(); 314 314 if (LIKELY(v.isString())) 315 315 result.append(asString(v)->value()); 316 else if (v.isInt32()) 317 result.appendNumeric(v.asInt32()); 318 else { 319 double d; 320 if (v.getNumber(d)) 321 result.appendNumeric(d); 322 else 323 result.append(v.toString(callFrame)); 324 } 316 else 317 result.append(v.toString(callFrame)); 325 318 } 326 319 -
trunk/JavaScriptCore/runtime/UString.cpp
r47102 r47622 1028 1028 if (isnan(d)) 1029 1029 return "NaN"; 1030 if (!d) 1031 return "0"; // -0 -> "0" 1030 1032 1031 1033 char buf[80]; … … 1210 1212 } 1211 1213 1212 UString& UString::appendNumeric(int i)1213 {1214 m_rep = concatenate(rep(), i);1215 return *this;1216 }1217 1218 UString& UString::appendNumeric(double d)1219 {1220 m_rep = concatenate(rep(), d);1221 return *this;1222 }1223 1224 1214 UString& UString::append(const char* t) 1225 1215 { -
trunk/JavaScriptCore/runtime/UString.h
r47096 r47622 288 288 UString& append(char c) { return append(static_cast<UChar>(static_cast<unsigned char>(c))); } 289 289 UString& append(const UChar*, int size); 290 UString& appendNumeric(int);291 UString& appendNumeric(double);292 290 293 291 bool getCString(CStringBuffer&) const;
Note:
See TracChangeset
for help on using the changeset viewer.