Changeset 39747 in webkit for trunk/JavaScriptCore/runtime/UString.h
- Timestamp:
- Jan 9, 2009, 9:53:36 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.