Changeset 57932 in webkit for trunk/JavaScriptCore/runtime/UStringImpl.h
- Timestamp:
- Apr 20, 2010, 3:34:52 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UStringImpl.h
r57912 r57932 34 34 #include <wtf/Vector.h> 35 35 #include <wtf/unicode/Unicode.h> 36 #include <wtf/text/StringImplBase.h> 36 37 37 38 namespace JSC { … … 42 43 typedef CrossThreadRefCounted<SharableUChar> SharedUChar; 43 44 44 class UStringImplBase : public Noncopyable { 45 public: 46 bool isStringImpl() { return (m_refCountAndFlags & s_refCountInvalidForStringImpl) != s_refCountInvalidForStringImpl; } 47 unsigned length() const { return m_length; } 48 49 void ref() { m_refCountAndFlags += s_refCountIncrement; } 50 51 protected: 52 enum BufferOwnership { 53 BufferInternal, 54 BufferOwned, 55 BufferSubstring, 56 BufferShared, 57 }; 58 59 using Noncopyable::operator new; 60 void* operator new(size_t, void* inPlace) { return inPlace; } 61 62 // For SmallStringStorage, which allocates an array and uses an in-place new. 63 UStringImplBase() { } 64 65 UStringImplBase(unsigned length, BufferOwnership ownership) 66 : m_refCountAndFlags(s_refCountIncrement | s_refCountFlagShouldReportedCost | ownership) 67 , m_length(length) 68 { 69 ASSERT(isStringImpl()); 70 } 71 72 enum StaticStringConstructType { ConstructStaticString }; 73 UStringImplBase(unsigned length, StaticStringConstructType) 74 : m_refCountAndFlags(s_refCountFlagStatic | s_refCountFlagIsIdentifier | BufferOwned) 75 , m_length(length) 76 { 77 ASSERT(isStringImpl()); 78 } 79 80 // This constructor is not used when creating UStringImpl objects, 81 // and sets the flags into a state marking the object as such. 82 enum NonStringImplConstructType { ConstructNonStringImpl }; 83 UStringImplBase(NonStringImplConstructType) 84 : m_refCountAndFlags(s_refCountIncrement | s_refCountInvalidForStringImpl) 85 , m_length(0) 86 { 87 ASSERT(!isStringImpl()); 88 } 89 90 // The bottom 5 bits hold flags, the top 27 bits hold the ref count. 91 // When dereferencing UStringImpls we check for the ref count AND the 92 // static bit both being zero - static strings are never deleted. 93 static const unsigned s_refCountMask = 0xFFFFFFE0; 94 static const unsigned s_refCountIncrement = 0x20; 95 static const unsigned s_refCountFlagStatic = 0x10; 96 static const unsigned s_refCountFlagShouldReportedCost = 0x8; 97 static const unsigned s_refCountFlagIsIdentifier = 0x4; 98 static const unsigned s_refCountMaskBufferOwnership = 0x3; 99 // An invalid permutation of flags (static & shouldReportedCost - static strings do not 100 // set shouldReportedCost in the constructor, and this bit is only ever cleared, not set). 101 // Used by "ConstructNonStringImpl" constructor, above. 102 static const unsigned s_refCountInvalidForStringImpl = s_refCountFlagStatic | s_refCountFlagShouldReportedCost; 103 104 unsigned m_refCountAndFlags; 105 unsigned m_length; 106 }; 107 108 class UStringImpl : public UStringImplBase { 45 class UStringImpl : public StringImplBase { 109 46 friend struct CStringTranslator; 110 47 friend struct UCharBufferTranslator; … … 120 57 // static strings will be shared across threads & ref-counted in a non-threadsafe manner. 121 58 UStringImpl(const UChar* characters, unsigned length, StaticStringConstructType) 122 : UStringImplBase(length, ConstructStaticString)59 : StringImplBase(length, ConstructStaticString) 123 60 , m_data(characters) 124 61 , m_buffer(0) … … 130 67 // Create a normal string with internal storage (BufferInternal) 131 68 UStringImpl(unsigned length) 132 : UStringImplBase(length, BufferInternal)69 : StringImplBase(length, BufferInternal) 133 70 , m_data(reinterpret_cast<UChar*>(this + 1)) 134 71 , m_buffer(0) … … 141 78 // Create a UStringImpl adopting ownership of the provided buffer (BufferOwned) 142 79 UStringImpl(const UChar* characters, unsigned length) 143 : UStringImplBase(length, BufferOwned)80 : StringImplBase(length, BufferOwned) 144 81 , m_data(characters) 145 82 , m_buffer(0) … … 152 89 // Used to create new strings that are a substring of an existing UStringImpl (BufferSubstring) 153 90 UStringImpl(const UChar* characters, unsigned length, PassRefPtr<UStringImpl> base) 154 : UStringImplBase(length, BufferSubstring)91 : StringImplBase(length, BufferSubstring) 155 92 , m_data(characters) 156 93 , m_substringBuffer(base.releaseRef()) … … 164 101 // Used to construct new strings sharing an existing SharedUChar (BufferShared) 165 102 UStringImpl(const UChar* characters, unsigned length, PassRefPtr<SharedUChar> sharedBuffer) 166 : UStringImplBase(length, BufferShared)103 : StringImplBase(length, BufferShared) 167 104 , m_data(characters) 168 105 , m_sharedBuffer(sharedBuffer.releaseRef())
Note:
See TracChangeset
for help on using the changeset viewer.