Changeset 53447 in webkit
- Timestamp:
- Jan 18, 2010 6:22:37 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r53446 r53447 1 2010-01-15 Gavin Barraclough <barraclough@apple.com> 2 3 Reviewed by Darin Adler & Oliver Hunt. 4 5 https://bugs.webkit.org/show_bug.cgi?id=33731 6 Remove uses of PtrAndFlags from WebCore::StringImpl. 7 8 These break the OS X Leaks tool. Move the management of null-terminated copies 9 out from StringImpl to String, and use a bit stolen from the refCount to hold the 10 'InTable' flag. 11 12 * platform/sql/SQLiteFileSystem.cpp: 13 (WebCore::SQLiteFileSystem::openDatabase): 14 * platform/sql/SQLiteStatement.cpp: 15 (WebCore::SQLiteStatement::prepare): 16 * platform/sql/SQLiteStatement.h: 17 * platform/text/PlatformString.h: 18 * platform/text/String.cpp: 19 (WebCore::String::copyWithNullTermination): 20 * platform/text/StringImpl.cpp: 21 (WebCore::StringImpl::StringImpl): 22 (WebCore::StringImpl::~StringImpl): 23 (WebCore::StringImpl::create): 24 (WebCore::StringImpl::crossThreadString): 25 (WebCore::StringImpl::sharedBuffer): 26 * platform/text/StringImpl.h: 27 (WebCore::StringImpl::inTable): 28 (WebCore::StringImpl::setInTable): 29 1 30 2010-01-18 Nikolas Zimmermann <nzimmermann@rim.com> 2 31 -
trunk/WebCore/WebCore.base.exp
r53442 r53447 143 143 __ZN7WebCore10StringImplD1Ev 144 144 __ZN7WebCore10StringImplcvP8NSStringEv 145 __ZN7WebCore10StringImpldlEPv146 145 __ZN7WebCore10handCursorEv 147 146 __ZN7WebCore10setCookiesEPNS_8DocumentERKNS_4KURLERKNS_6StringE -
trunk/WebCore/platform/text/StringImpl.cpp
r53418 r53447 58 58 } 59 59 60 // Some of the factory methods create buffers using fastMalloc.61 // We must ensure that all allocations of StringImpl are allocated using62 // fastMalloc so that we don't have mis-matched frees. We accomplish63 // this by overriding the new and delete operators.64 void* StringImpl::operator new(size_t size, void* address)65 {66 if (address)67 return address; // Allocating using an internal buffer68 return fastMalloc(size);69 }70 71 void* StringImpl::operator new(size_t size)72 {73 return fastMalloc(size);74 }75 76 void StringImpl::operator delete(void* address)77 {78 fastFree(address);79 }80 81 60 // This constructor is used only to create the empty string. 82 61 StringImpl::StringImpl() 83 62 : m_data(0) 63 , m_sharedBuffer(0) 84 64 , m_length(0) 65 , m_refCountAndFlags(s_refCountIncrement) 85 66 , m_hash(0) 86 67 { … … 93 74 inline StringImpl::StringImpl(const UChar* characters, unsigned length) 94 75 : m_data(characters) 76 , m_sharedBuffer(0) 95 77 , m_length(length) 78 , m_refCountAndFlags(s_refCountIncrement) 96 79 , m_hash(0) 97 80 { … … 105 88 AtomicString::remove(this); 106 89 if (!bufferIsInternal()) { 107 SharedUChar* sharedBuffer = m_sharedBuffer AndFlags.get();90 SharedUChar* sharedBuffer = m_sharedBuffer; 108 91 if (sharedBuffer) 109 92 sharedBuffer->deref(); … … 971 954 PassRefPtr<StringImpl> impl = adoptRef(new StringImpl(str.data(), str.size())); 972 955 sharedBuffer->ref(); 973 impl->m_sharedBuffer AndFlags.set(sharedBuffer);956 impl->m_sharedBuffer = sharedBuffer; 974 957 return impl; 975 958 } … … 998 981 terminatedString->m_length--; 999 982 terminatedString->m_hash = string.m_hash; 1000 terminatedString->m_ sharedBufferAndFlags.setFlag(HasTerminatingNullCharacter);983 terminatedString->m_refCountAndFlags |= s_refCountFlagHasTerminatingNullCharacter; 1001 984 return terminatedString.release(); 1002 985 } … … 1015 998 if (shared) { 1016 999 RefPtr<StringImpl> impl = adoptRef(new StringImpl(m_data, m_length)); 1017 impl->m_sharedBuffer AndFlags.set(shared->crossThreadCopy().releaseRef());1000 impl->m_sharedBuffer = shared->crossThreadCopy().releaseRef(); 1018 1001 return impl.release(); 1019 1002 } … … 1028 1011 return 0; 1029 1012 1030 if (!m_sharedBuffer AndFlags.get())1031 m_sharedBuffer AndFlags.set(SharedUChar::create(new OwnFastMallocPtr<UChar>(const_cast<UChar*>(m_data))).releaseRef());1032 return m_sharedBuffer AndFlags.get();1013 if (!m_sharedBuffer) 1014 m_sharedBuffer = SharedUChar::create(new OwnFastMallocPtr<UChar>(const_cast<UChar*>(m_data))).releaseRef(); 1015 return m_sharedBuffer; 1033 1016 } 1034 1017 -
trunk/WebCore/platform/text/StringImpl.h
r53418 r53447 27 27 #include <wtf/ASCIICType.h> 28 28 #include <wtf/CrossThreadRefCounted.h> 29 #include <wtf/Noncopyable.h> 29 30 #include <wtf/OwnFastMallocPtr.h> 30 #include <wtf/PtrAndFlags.h>31 31 #include <wtf/RefCounted.h> 32 32 #include <wtf/StringHashFunctions.h> … … 59 59 typedef bool (*CharacterMatchFunctionPtr)(UChar); 60 60 61 class StringImpl : public RefCounted<StringImpl>{61 class StringImpl : public Noncopyable { 62 62 friend struct CStringTranslator; 63 63 friend struct HashAndCharactersTranslator; … … 97 97 unsigned length() { return m_length; } 98 98 99 bool hasTerminatingNullCharacter() const { return m_ sharedBufferAndFlags.isFlagSet(HasTerminatingNullCharacter); }100 101 bool inTable() const { return m_ sharedBufferAndFlags.isFlagSet(InTable); }102 void setInTable() { return m_sharedBufferAndFlags.setFlag(InTable); }99 bool hasTerminatingNullCharacter() const { return m_refCountAndFlags & s_refCountFlagHasTerminatingNullCharacter; } 100 101 bool inTable() const { return m_refCountAndFlags & s_refCountFlagInTable; } 102 void setInTable() { m_refCountAndFlags |= s_refCountFlagInTable; } 103 103 104 104 unsigned hash() { if (m_hash == 0) m_hash = computeHash(m_data, m_length); return m_hash; } … … 107 107 inline static unsigned computeHash(const char* data) { return WTF::stringHash(data); } 108 108 109 StringImpl* ref() { m_refCountAndFlags += s_refCountIncrement; return this; } 110 ALWAYS_INLINE void deref() { m_refCountAndFlags -= s_refCountIncrement; if (!(m_refCountAndFlags & s_refCountMask)) delete this; } 111 ALWAYS_INLINE bool hasOneRef() const { return (m_refCountAndFlags & s_refCountMask) == s_refCountIncrement; } 112 109 113 // Returns a StringImpl suitable for use on another thread. 110 114 PassRefPtr<StringImpl> crossThreadString(); … … 176 180 #endif 177 181 178 void operator delete(void*);179 180 182 private: 181 // Allocation from a custom buffer is only allowed internally to avoid 182 // mismatched allocators. Callers should use create(). 183 void* operator new(size_t size); 184 void* operator new(size_t size, void* address); 183 using Noncopyable::operator new; 184 void* operator new(size_t, void* inPlace) { ASSERT(inPlace); return inPlace; } 185 185 186 186 static PassRefPtr<StringImpl> createStrippingNullCharactersSlowCase(const UChar*, unsigned length); … … 190 190 bool bufferIsInternal() { return m_data == reinterpret_cast<const UChar*>(this + 1); } 191 191 192 enum StringImplFlags {193 HasTerminatingNullCharacter,194 InTable,195 };192 static const unsigned s_refCountMask = 0xFFFFFFFC; 193 static const unsigned s_refCountIncrement = 0x4; 194 static const unsigned s_refCountFlagHasTerminatingNullCharacter = 0x2; 195 static const unsigned s_refCountFlagInTable = 0x1; 196 196 197 197 const UChar* m_data; 198 SharedUChar* m_sharedBuffer; 198 199 unsigned m_length; 200 unsigned m_refCountAndFlags; 199 201 mutable unsigned m_hash; 200 PtrAndFlags<SharedUChar, StringImplFlags> m_sharedBufferAndFlags;201 202 // There is a fictitious variable-length UChar array at the end, which is used 202 203 // as the internal buffer by the createUninitialized and create methods. -
trunk/WebCore/storage/OriginUsageRecord.cpp
r53418 r53447 43 43 { 44 44 ASSERT(!m_databaseMap.contains(identifier)); 45 ASSERT_ARG(identifier, identifier.impl()-> refCount() == 1);46 ASSERT_ARG(fullPath, fullPath.impl()-> refCount() == 1);45 ASSERT_ARG(identifier, identifier.impl()->hasOneRef()); 46 ASSERT_ARG(fullPath, fullPath.impl()->hasOneRef()); 47 47 48 48 m_databaseMap.set(identifier, DatabaseEntry(fullPath)); … … 64 64 { 65 65 ASSERT(m_databaseMap.contains(identifier)); 66 ASSERT_ARG(identifier, identifier.impl()-> refCount() == 1);66 ASSERT_ARG(identifier, identifier.impl()->hasOneRef()); 67 67 68 68 m_unknownSet.add(identifier);
Note: See TracChangeset
for help on using the changeset viewer.