Changeset 39747 in webkit for trunk/JavaScriptCore/runtime
- Timestamp:
- Jan 9, 2009, 9:53:36 AM (16 years ago)
- Location:
- trunk/JavaScriptCore/runtime
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/Identifier.cpp
r39350 r39747 125 125 { 126 126 if (!c) { 127 UString::Rep::null .hash();128 return &UString::Rep::null ;127 UString::Rep::null().hash(); 128 return &UString::Rep::null(); 129 129 } 130 130 if (!c[0]) { 131 UString::Rep::empty .hash();132 return &UString::Rep::empty ;131 UString::Rep::empty().hash(); 132 return &UString::Rep::empty(); 133 133 } 134 134 if (!c[1]) … … 195 195 } 196 196 if (!length) { 197 UString::Rep::empty .hash();198 return &UString::Rep::empty ;197 UString::Rep::empty().hash(); 198 return &UString::Rep::empty(); 199 199 } 200 200 UCharBuffer buf = {s, length}; … … 226 226 } 227 227 if (!r->len) { 228 UString::Rep::empty .hash();229 return &UString::Rep::empty ;228 UString::Rep::empty().hash(); 229 return &UString::Rep::empty(); 230 230 } 231 231 return *globalData->identifierTable->add(r).first; -
trunk/JavaScriptCore/runtime/InitializeThreading.cpp
r39670 r39747 50 50 { 51 51 WTF::initializeThreading(); 52 initializeUString(); 52 53 #if ENABLE(JSC_MULTIPLE_THREADS) 53 54 s_dtoaP5Mutex = new Mutex; 54 UString::null();55 55 initDateMath(); 56 56 #endif -
trunk/JavaScriptCore/runtime/JSGlobalData.cpp
r38622 r39747 31 31 32 32 #include "ArgList.h" 33 #include "Collector.h" 33 34 #include "CommonIdentifiers.h" 35 #include "InitializeThreading.h" 36 #include "Interpreter.h" 34 37 #include "JSActivation.h" 35 38 #include "JSClassRef.h" … … 37 40 #include "JSNotAnObject.h" 38 41 #include "JSStaticScopeObject.h" 39 #include "Interpreter.h"40 42 #include "Parser.h" 41 #include "Collector.h"42 43 #include "Lexer.h" 43 44 #include "Lookup.h" … … 143 144 PassRefPtr<JSGlobalData> JSGlobalData::create() 144 145 { 146 initializeThreading(); 145 147 return adoptRef(new JSGlobalData); 146 148 } -
trunk/JavaScriptCore/runtime/PropertyNameArray.cpp
r38087 r39747 28 28 void PropertyNameArray::add(UString::Rep* identifier) 29 29 { 30 ASSERT(identifier == &UString::Rep::null || identifier == &UString::Rep::empty|| identifier->identifierTable());30 ASSERT(identifier == &UString::Rep::null() || identifier == &UString::Rep::empty() || identifier->identifierTable()); 31 31 32 32 size_t size = m_data->propertyNameVector().size(); -
trunk/JavaScriptCore/runtime/UString.cpp
r38390 r39747 3 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 4 4 * Copyright (C) 2007 Cameron Zwarich ([email protected]) 5 * Copyright (c) 2009, Google Inc. All rights reserved. 5 6 * 6 7 * This library is free software; you can redistribute it and/or … … 187 188 // reduce the possibility of it becoming zero due to ref/deref not being thread-safe. 188 189 static UChar sharedEmptyChar; 189 UString::Rep UString::Rep::null = { 0, 0, INT_MAX / 2, 0, 1, &UString::Rep::null, 0, 0, 0, 0, 0, 0 }; 190 UString::Rep UString::Rep::empty = { 0, 0, INT_MAX / 2, 0, 1, &UString::Rep::empty, 0, &sharedEmptyChar, 0, 0, 0, 0 }; 190 UString::Rep* UString::Rep::nullBaseString; 191 UString::Rep* UString::Rep::emptyBaseString; 192 UString* UString::nullUString; 193 194 void initializeStaticBaseString(int len, UChar* buf, UString::Rep& base) 195 { 196 base.offset = 0; 197 base.len = len; 198 base.rc = INT_MAX / 2; 199 base._hash = 0; 200 base.m_identifierTableAndFlags.setFlag(UString::Rep::StaticFlag); 201 base.baseString = &base; 202 base.buf = buf; 203 base.preCapacity = 0; 204 base.usedPreCapacity = 0; 205 base.capacity = 0; 206 base.usedCapacity = 0; 207 base.reportedCost = 0; 208 } 209 210 void initializeUString() 211 { 212 UString::Rep::nullBaseString = new UString::Rep; 213 initializeStaticBaseString(0, 0, *UString::Rep::nullBaseString); 214 215 UString::Rep::emptyBaseString = new UString::Rep; 216 initializeStaticBaseString(0, &sharedEmptyChar, *UString::Rep::emptyBaseString); 217 218 UString::nullUString = new UString; 219 } 191 220 192 221 static char* statBuffer = 0; // Only used for debugging via UString::ascii(). … … 206 235 r->rc = 1; 207 236 r->_hash = 0; 208 r->m_identifierTable = 0;209 237 r->baseString = r; 210 238 r->reportedCost = 0; … … 238 266 r->rc = 1; 239 267 r->_hash = 0; 240 r->m_identifierTable = 0;241 268 r->baseString = base.releaseRef(); 242 269 r->reportedCost = 0; … … 256 283 { 257 284 if (!string) 258 return &UString::Rep::null ;285 return &UString::Rep::null(); 259 286 260 287 size_t length = strlen(string); … … 262 289 UChar* p = buffer.data(); 263 290 if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length)) 264 return &UString::Rep::null ;291 return &UString::Rep::null(); 265 292 266 293 return UString::Rep::createCopying(buffer.data(), p - buffer.data()); … … 495 522 { 496 523 if (!c) 497 return &UString::Rep::null ;524 return &UString::Rep::null(); 498 525 499 526 if (!c[0]) 500 return &UString::Rep::empty ;527 return &UString::Rep::empty(); 501 528 502 529 size_t length = strlen(c); 503 530 UChar* d = allocChars(length); 504 531 if (!d) 505 return &UString::Rep::null ;532 return &UString::Rep::null(); 506 533 else { 507 534 for (size_t i = 0; i < length; i++) … … 520 547 { 521 548 if (length == 0) 522 m_rep = &Rep::empty ;549 m_rep = &Rep::empty(); 523 550 else 524 551 m_rep = Rep::createCopying(c, length); … … 528 555 { 529 556 if (length == 0) 530 m_rep = &Rep::empty ;557 m_rep = &Rep::empty(); 531 558 else if (copy) 532 559 m_rep = Rep::createCopying(c, length); … … 538 565 { 539 566 if (!buffer.size()) 540 m_rep = &Rep::empty ;567 m_rep = &Rep::empty(); 541 568 else 542 569 m_rep = Rep::createCopying(buffer.data(), buffer.size()); … … 562 589 // this is direct and has refcount of 1 (so we can just alter it directly) 563 590 if (!expandCapacity(rep.get(), thisOffset + length)) 564 rep = &UString::Rep::null ;591 rep = &UString::Rep::null(); 565 592 if (rep->data()) { 566 593 copyChars(rep->data() + thisSize, tData, tSize); … … 571 598 // this reaches the end of the buffer - extend it if it's long enough to append to 572 599 if (!expandCapacity(rep.get(), thisOffset + length)) 573 rep = &UString::Rep::null ;600 rep = &UString::Rep::null(); 574 601 if (rep->data()) { 575 602 copyChars(rep->data() + thisSize, tData, tSize); … … 581 608 UChar* d = allocChars(newCapacity); 582 609 if (!d) 583 rep = &UString::Rep::null ;610 rep = &UString::Rep::null(); 584 611 else { 585 612 copyChars(d, rep->data(), thisSize); … … 636 663 UChar* d = allocChars(newCapacity); 637 664 if (!d) 638 rep = &UString::Rep::null ;665 rep = &UString::Rep::null(); 639 666 else { 640 667 copyChars(d, rep->data(), thisSize); … … 832 859 } 833 860 834 const UString& UString::null()835 {836 static UString* n = new UString; // Should be called from main thread at least once to be safely initialized.837 return *n;838 }839 840 861 UString UString::from(int i) 841 862 { … … 1186 1207 { 1187 1208 if (!c) { 1188 m_rep = &Rep::null ;1209 m_rep = &Rep::null(); 1189 1210 return *this; 1190 1211 } 1191 1212 1192 1213 if (!c[0]) { 1193 m_rep = &Rep::empty ;1214 m_rep = &Rep::empty(); 1194 1215 return *this; 1195 1216 } … … 1627 1648 NEVER_INLINE void UString::makeNull() 1628 1649 { 1629 m_rep = &Rep::null ;1650 m_rep = &Rep::null(); 1630 1651 } 1631 1652 … … 1633 1654 NEVER_INLINE UString::Rep* UString::nullRep() 1634 1655 { 1635 return &Rep::null ;1656 return &Rep::null(); 1636 1657 } 1637 1658 -
trunk/JavaScriptCore/runtime/UString.h
r39554 r39747 2 2 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 3 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 4 * Copyright (c) 2009, Google Inc. All rights reserved. 4 5 * 5 6 * This library is free software; you can redistribute it and/or … … 29 30 #include <wtf/FastMalloc.h> 30 31 #include <wtf/PassRefPtr.h> 32 #include <wtf/PtrAndFlags.h> 31 33 #include <wtf/RefPtr.h> 32 34 #include <wtf/Vector.h> … … 99 101 static unsigned computeHash(const char* s) { return computeHash(s, strlen(s)); } 100 102 101 IdentifierTable* identifierTable() const { return reinterpret_cast<IdentifierTable*>(m_identifierTable & ~static_cast<uintptr_t>(1)); }102 void setIdentifierTable(IdentifierTable* table) { ASSERT(!isStatic()); m_identifierTable = reinterpret_cast<intptr_t>(table); }103 104 bool isStatic() const { return m_identifierTable & 1; }105 void setStatic(bool v) { ASSERT(!identifierTable()); m_identifierTable = v; }103 IdentifierTable* identifierTable() const { return m_identifierTableAndFlags.get(); } 104 void setIdentifierTable(IdentifierTable* table) { ASSERT(!isStatic()); m_identifierTableAndFlags.set(table); } 105 106 bool isStatic() const { return m_identifierTableAndFlags.isFlagSet(StaticFlag); } 107 void setStatic(bool v) { ASSERT(!identifierTable()); if (v) m_identifierTableAndFlags.setFlag(StaticFlag); else m_identifierTableAndFlags.clearFlag(StaticFlag); } 106 108 107 109 Rep* ref() { ++rc; return this; } … … 109 111 110 112 void checkConsistency() const; 113 enum UStringFlags { 114 StaticFlag 115 }; 111 116 112 117 // unshared data … … 115 120 int rc; // For null and empty static strings, this field does not reflect a correct count, because ref/deref are not thread-safe. A special case in destroy() guarantees that these do not get deleted. 116 121 mutable unsigned _hash; 117 intptr_t m_identifierTable; // A pointer to identifier table. The lowest bit is used to indicate whether the string is static (null or empty).122 PtrAndFlags<IdentifierTable, UStringFlags> m_identifierTableAndFlags; 118 123 UString::Rep* baseString; 119 124 size_t reportedCost; … … 126 131 int preCapacity; 127 132 128 static Rep null; 129 static Rep empty; 133 static Rep& null() { return *nullBaseString; } 134 static Rep& empty() { return *emptyBaseString; } 135 private: 136 friend void initializeUString(); 137 static Rep* nullBaseString; 138 static Rep* emptyBaseString; 130 139 }; 131 140 … … 205 214 const UChar* data() const { return m_rep->data(); } 206 215 207 bool isNull() const { return (m_rep == &Rep::null ); }216 bool isNull() const { return (m_rep == &Rep::null()); } 208 217 bool isEmpty() const { return (!m_rep->len); } 209 218 … … 231 240 UString substr(int pos = 0, int len = -1) const; 232 241 233 static const UString& null() ;242 static const UString& null() { return *nullUString; } 234 243 235 244 Rep* rep() const { return m_rep.get(); } … … 252 261 253 262 RefPtr<Rep> m_rep; 254 263 static UString* nullUString; 264 265 friend void initializeUString(); 255 266 friend bool operator==(const UString&, const UString&); 256 267 friend PassRefPtr<Rep> concatenate(Rep*, Rep*); // returns 0 if out of memory … … 306 317 307 318 inline UString::UString() 308 : m_rep(&Rep::null )319 : m_rep(&Rep::null()) 309 320 { 310 321 } … … 348 359 }; 349 360 361 void initializeUString(); 350 362 } // namespace JSC 351 363
Note:
See TracChangeset
for help on using the changeset viewer.