Changeset 53320 in webkit for trunk/JavaScriptCore/runtime/UStringImpl.h
- Timestamp:
- Jan 14, 2010, 10:43:21 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UStringImpl.h
r53221 r53320 32 32 #include <wtf/PossiblyNull.h> 33 33 #include <wtf/StringHashFunctions.h> 34 #include <wtf/Vector.h> 34 35 #include <wtf/unicode/Unicode.h> 35 36 … … 84 85 class UStringImpl : Noncopyable { 85 86 public: 86 static PassRefPtr<UStringImpl> create(UChar* buffer, int length) 87 { 88 return adoptRef(new UStringImpl(buffer, length, BufferOwned)); 89 } 90 91 static PassRefPtr<UStringImpl> createCopying(const UChar* buffer, int length) 87 template<size_t inlineCapacity> 88 static PassRefPtr<UStringImpl> adopt(Vector<UChar, inlineCapacity>& vector) 89 { 90 if (unsigned length = vector.size()) 91 return adoptRef(new UStringImpl(vector.releaseBuffer(), length, BufferOwned)); 92 return &empty(); 93 } 94 95 static PassRefPtr<UStringImpl> create(const UChar* buffer, int length) 92 96 { 93 97 UChar* newBuffer; … … 112 116 static PassRefPtr<UStringImpl> createUninitialized(unsigned length, UChar*& output) 113 117 { 114 ASSERT(length); 118 if (!length) { 119 output = 0; 120 return &empty(); 121 } 122 123 if (length > ((std::numeric_limits<size_t>::max() - sizeof(UStringImpl)) / sizeof(UChar))) 124 CRASH(); 125 UStringImpl* resultImpl = static_cast<UStringImpl*>(fastMalloc(sizeof(UChar) * length + sizeof(UStringImpl))); 126 output = reinterpret_cast<UChar*>(resultImpl + 1); 127 return adoptRef(new(resultImpl) UStringImpl(output, length, BufferInternal)); 128 } 129 130 static PassRefPtr<UStringImpl> tryCreateUninitialized(unsigned length, UChar*& output) 131 { 132 if (!length) { 133 output = 0; 134 return &empty(); 135 } 136 115 137 if (length > ((std::numeric_limits<size_t>::max() - sizeof(UStringImpl)) / sizeof(UChar))) 116 138 return 0; 117 118 139 UStringImpl* resultImpl; 119 140 if (!tryFastMalloc(sizeof(UChar) * length + sizeof(UStringImpl)).getValue(resultImpl)) 120 141 return 0; 121 122 142 output = reinterpret_cast<UChar*>(resultImpl + 1); 123 143 return adoptRef(new(resultImpl) UStringImpl(output, length, BufferInternal)); … … 139 159 } 140 160 unsigned hash() const { if (!m_hash) m_hash = computeHash(data(), m_length); return m_hash; } 141 unsigned computedHash() const { ASSERT(m_hash); return m_hash; } // fast path for Identifiers161 unsigned existingHash() const { ASSERT(m_hash); return m_hash; } // fast path for Identifiers 142 162 void setHash(unsigned hash) { ASSERT(hash == computeHash(data(), m_length)); m_hash = hash; } // fast path for Identifiers 143 163 bool isIdentifier() const { return m_isIdentifier; }
Note:
See TracChangeset
for help on using the changeset viewer.