Changeset 42282 in webkit for trunk/JavaScriptCore/runtime/UString.h
- Timestamp:
- Apr 7, 2009, 2:15:33 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.h
r39815 r42282 80 80 friend class JIT; 81 81 82 static PassRefPtr<Rep> create(UChar*, int); 82 static PassRefPtr<Rep> create(UChar* buffer, int length) 83 { 84 return adoptRef(new BaseString(buffer, length)); 85 } 86 83 87 static PassRefPtr<Rep> createCopying(const UChar*, int); 84 88 static PassRefPtr<Rep> create(PassRefPtr<Rep> base, int offset, int length); … … 125 129 mutable unsigned _hash; 126 130 PtrAndFlags<IdentifierTable, UStringFlags> m_identifierTableAndFlags; 127 void* m_baseString; // If "this" is a BaseString instance, it is 0. BaseString* otherwise.128 131 129 132 static BaseString& null() { return *nullBaseString; } 130 133 static BaseString& empty() { return *emptyBaseString; } 131 134 135 protected: 136 Rep(int length) 137 : offset(0) 138 , len(length) 139 , rc(1) 140 , _hash(0) 141 , m_nothing(0) 142 { 143 } 144 145 Rep(PassRefPtr<BaseString> base, int offsetInBase, int length) 146 : offset(offsetInBase) 147 , len(length) 148 , rc(1) 149 , _hash(0) 150 , m_baseString(base.releaseRef()) 151 { 152 checkConsistency(); 153 } 154 155 union { 156 // If !baseIsSelf() 157 BaseString* m_baseString; 158 // If baseIsSelf() 159 void* m_nothing; 160 }; 161 132 162 private: 163 // For SmallStringStorage which allocates an array and does initialization manually. 164 Rep() { } 165 166 friend class SmallStringsStorage; 133 167 friend void initializeUString(); 134 168 static BaseString* nullBaseString; … … 136 170 }; 137 171 172 138 173 struct BaseString : public Rep { 139 BaseString() 140 { 141 m_identifierTableAndFlags.setFlag(BaseStringFlag); 142 } 174 bool isShared() { return rc != 1; } 143 175 144 176 // potentially shared data. … … 150 182 151 183 size_t reportedCost; 184 185 private: 186 BaseString(UChar* buffer, int length) 187 : Rep(length) 188 , buf(buffer) 189 , preCapacity(0) 190 , usedPreCapacity(0) 191 , capacity(length) 192 , usedCapacity(length) 193 , reportedCost(0) 194 { 195 m_identifierTableAndFlags.setFlag(BaseStringFlag); 196 checkConsistency(); 197 } 198 199 friend struct Rep; 200 friend class SmallStringsStorage; 201 friend void initializeUString(); 152 202 }; 153 203 … … 321 371 bool equal(const UString::Rep*, const UString::Rep*); 322 372 373 inline PassRefPtr<UString::Rep> UString::Rep::create(PassRefPtr<UString::Rep> rep, int offset, int length) 374 { 375 ASSERT(rep); 376 rep->checkConsistency(); 377 378 int repOffset = rep->offset; 379 380 PassRefPtr<BaseString> base = rep->baseString(); 381 382 ASSERT(-(offset + repOffset) <= base->usedPreCapacity); 383 ASSERT(offset + repOffset + length <= base->usedCapacity); 384 385 // Steal the single reference this Rep was created with. 386 return adoptRef(new Rep(base, repOffset + offset, length)); 387 } 388 323 389 inline UChar* UString::Rep::data() const 324 390 { … … 339 405 { 340 406 ASSERT(base != this); 407 ASSERT(!baseIsSelf()); 341 408 m_baseString = base.releaseRef(); 342 409 } … … 344 411 inline UString::BaseString* UString::Rep::baseString() 345 412 { 346 return reinterpret_cast<BaseString*>(baseIsSelf() ? this : m_baseString);413 return baseIsSelf() ? reinterpret_cast<BaseString*>(this) : m_baseString; 347 414 } 348 415 349 416 inline const UString::BaseString* UString::Rep::baseString() const 350 417 { 351 return const_cast< const BaseString*>(const_cast<Rep*>(this)->baseString());418 return const_cast<Rep*>(this)->baseString(); 352 419 } 353 420
Note:
See TracChangeset
for help on using the changeset viewer.