[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373
barraclough at apple.com
barraclough at apple.com
Thu Apr 8 01:14:04 UTC 2010
The following commit has been merged in the webkit-1.2 branch:
commit 0c9e8da75a1c0d041d1e3849d195d7dabf1e6bfb
Author: barraclough at apple.com <barraclough at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Jan 19 02:22:37 2010 +0000
https://bugs.webkit.org/show_bug.cgi?id=33731
Remove uses of PtrAndFlags from WebCore::StringImpl.
Reviewed by Darin Adler & Oliver Hunt.
These break the OS X Leaks tool. Move the management of null-terminated copies
out from StringImpl to String, and use a bit stolen from the refCount to hold the
'InTable' flag.
* platform/sql/SQLiteFileSystem.cpp:
(WebCore::SQLiteFileSystem::openDatabase):
* platform/sql/SQLiteStatement.cpp:
(WebCore::SQLiteStatement::prepare):
* platform/sql/SQLiteStatement.h:
* platform/text/PlatformString.h:
* platform/text/String.cpp:
(WebCore::String::copyWithNullTermination):
* platform/text/StringImpl.cpp:
(WebCore::StringImpl::StringImpl):
(WebCore::StringImpl::~StringImpl):
(WebCore::StringImpl::create):
(WebCore::StringImpl::crossThreadString):
(WebCore::StringImpl::sharedBuffer):
* platform/text/StringImpl.h:
(WebCore::StringImpl::inTable):
(WebCore::StringImpl::setInTable):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53447 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index d260e17..6a8caf5 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,32 @@
+2010-01-15 Gavin Barraclough <barraclough at apple.com>
+
+ Reviewed by Darin Adler & Oliver Hunt.
+
+ https://bugs.webkit.org/show_bug.cgi?id=33731
+ Remove uses of PtrAndFlags from WebCore::StringImpl.
+
+ These break the OS X Leaks tool. Move the management of null-terminated copies
+ out from StringImpl to String, and use a bit stolen from the refCount to hold the
+ 'InTable' flag.
+
+ * platform/sql/SQLiteFileSystem.cpp:
+ (WebCore::SQLiteFileSystem::openDatabase):
+ * platform/sql/SQLiteStatement.cpp:
+ (WebCore::SQLiteStatement::prepare):
+ * platform/sql/SQLiteStatement.h:
+ * platform/text/PlatformString.h:
+ * platform/text/String.cpp:
+ (WebCore::String::copyWithNullTermination):
+ * platform/text/StringImpl.cpp:
+ (WebCore::StringImpl::StringImpl):
+ (WebCore::StringImpl::~StringImpl):
+ (WebCore::StringImpl::create):
+ (WebCore::StringImpl::crossThreadString):
+ (WebCore::StringImpl::sharedBuffer):
+ * platform/text/StringImpl.h:
+ (WebCore::StringImpl::inTable):
+ (WebCore::StringImpl::setInTable):
+
2010-01-18 Nikolas Zimmermann <nzimmermann at rim.com>
Reviewed by Dirk Schulze.
diff --git a/WebCore/WebCore.base.exp b/WebCore/WebCore.base.exp
index e16c5f9..76597df 100644
--- a/WebCore/WebCore.base.exp
+++ b/WebCore/WebCore.base.exp
@@ -142,7 +142,6 @@ __ZN7WebCore10StringImpl7replaceEtt
__ZN7WebCore10StringImpl8endsWithEPS0_b
__ZN7WebCore10StringImplD1Ev
__ZN7WebCore10StringImplcvP8NSStringEv
-__ZN7WebCore10StringImpldlEPv
__ZN7WebCore10handCursorEv
__ZN7WebCore10setCookiesEPNS_8DocumentERKNS_4KURLERKNS_6StringE
__ZN7WebCore11BitmapImageC1EP7CGImagePNS_13ImageObserverE
diff --git a/WebCore/platform/text/StringImpl.cpp b/WebCore/platform/text/StringImpl.cpp
index 3b61a0b..1afa4d3 100644
--- a/WebCore/platform/text/StringImpl.cpp
+++ b/WebCore/platform/text/StringImpl.cpp
@@ -57,31 +57,12 @@ static inline void deleteUCharVector(const UChar* p)
fastFree(const_cast<UChar*>(p));
}
-// Some of the factory methods create buffers using fastMalloc.
-// We must ensure that all allocations of StringImpl are allocated using
-// fastMalloc so that we don't have mis-matched frees. We accomplish
-// this by overriding the new and delete operators.
-void* StringImpl::operator new(size_t size, void* address)
-{
- if (address)
- return address; // Allocating using an internal buffer
- return fastMalloc(size);
-}
-
-void* StringImpl::operator new(size_t size)
-{
- return fastMalloc(size);
-}
-
-void StringImpl::operator delete(void* address)
-{
- fastFree(address);
-}
-
// This constructor is used only to create the empty string.
StringImpl::StringImpl()
: m_data(0)
+ , m_sharedBuffer(0)
, m_length(0)
+ , m_refCountAndFlags(s_refCountIncrement)
, m_hash(0)
{
// Ensure that the hash is computed so that AtomicStringHash can call existingHash()
@@ -92,7 +73,9 @@ StringImpl::StringImpl()
inline StringImpl::StringImpl(const UChar* characters, unsigned length)
: m_data(characters)
+ , m_sharedBuffer(0)
, m_length(length)
+ , m_refCountAndFlags(s_refCountIncrement)
, m_hash(0)
{
ASSERT(characters);
@@ -104,7 +87,7 @@ StringImpl::~StringImpl()
if (inTable())
AtomicString::remove(this);
if (!bufferIsInternal()) {
- SharedUChar* sharedBuffer = m_sharedBufferAndFlags.get();
+ SharedUChar* sharedBuffer = m_sharedBuffer;
if (sharedBuffer)
sharedBuffer->deref();
else
@@ -970,7 +953,7 @@ PassRefPtr<StringImpl> StringImpl::create(const JSC::UString& str)
if (sharedBuffer) {
PassRefPtr<StringImpl> impl = adoptRef(new StringImpl(str.data(), str.size()));
sharedBuffer->ref();
- impl->m_sharedBufferAndFlags.set(sharedBuffer);
+ impl->m_sharedBuffer = sharedBuffer;
return impl;
}
return StringImpl::create(str.data(), str.size());
@@ -997,7 +980,7 @@ PassRefPtr<StringImpl> StringImpl::createWithTerminatingNullCharacter(const Stri
data[length] = 0;
terminatedString->m_length--;
terminatedString->m_hash = string.m_hash;
- terminatedString->m_sharedBufferAndFlags.setFlag(HasTerminatingNullCharacter);
+ terminatedString->m_refCountAndFlags |= s_refCountFlagHasTerminatingNullCharacter;
return terminatedString.release();
}
@@ -1014,7 +997,7 @@ PassRefPtr<StringImpl> StringImpl::crossThreadString()
SharedUChar* shared = sharedBuffer();
if (shared) {
RefPtr<StringImpl> impl = adoptRef(new StringImpl(m_data, m_length));
- impl->m_sharedBufferAndFlags.set(shared->crossThreadCopy().releaseRef());
+ impl->m_sharedBuffer = shared->crossThreadCopy().releaseRef();
return impl.release();
}
@@ -1027,9 +1010,9 @@ StringImpl::SharedUChar* StringImpl::sharedBuffer()
if (m_length < minLengthToShare || bufferIsInternal())
return 0;
- if (!m_sharedBufferAndFlags.get())
- m_sharedBufferAndFlags.set(SharedUChar::create(new OwnFastMallocPtr<UChar>(const_cast<UChar*>(m_data))).releaseRef());
- return m_sharedBufferAndFlags.get();
+ if (!m_sharedBuffer)
+ m_sharedBuffer = SharedUChar::create(new OwnFastMallocPtr<UChar>(const_cast<UChar*>(m_data))).releaseRef();
+ return m_sharedBuffer;
}
diff --git a/WebCore/platform/text/StringImpl.h b/WebCore/platform/text/StringImpl.h
index f7a9d06..a105985 100644
--- a/WebCore/platform/text/StringImpl.h
+++ b/WebCore/platform/text/StringImpl.h
@@ -26,8 +26,8 @@
#include <limits.h>
#include <wtf/ASCIICType.h>
#include <wtf/CrossThreadRefCounted.h>
+#include <wtf/Noncopyable.h>
#include <wtf/OwnFastMallocPtr.h>
-#include <wtf/PtrAndFlags.h>
#include <wtf/RefCounted.h>
#include <wtf/StringHashFunctions.h>
#include <wtf/Vector.h>
@@ -58,7 +58,7 @@ enum TextCaseSensitivity { TextCaseSensitive, TextCaseInsensitive };
typedef bool (*CharacterMatchFunctionPtr)(UChar);
-class StringImpl : public RefCounted<StringImpl> {
+class StringImpl : public Noncopyable {
friend struct CStringTranslator;
friend struct HashAndCharactersTranslator;
friend struct UCharBufferTranslator;
@@ -96,16 +96,20 @@ public:
const UChar* characters() { return m_data; }
unsigned length() { return m_length; }
- bool hasTerminatingNullCharacter() const { return m_sharedBufferAndFlags.isFlagSet(HasTerminatingNullCharacter); }
+ bool hasTerminatingNullCharacter() const { return m_refCountAndFlags & s_refCountFlagHasTerminatingNullCharacter; }
- bool inTable() const { return m_sharedBufferAndFlags.isFlagSet(InTable); }
- void setInTable() { return m_sharedBufferAndFlags.setFlag(InTable); }
+ bool inTable() const { return m_refCountAndFlags & s_refCountFlagInTable; }
+ void setInTable() { m_refCountAndFlags |= s_refCountFlagInTable; }
unsigned hash() { if (m_hash == 0) m_hash = computeHash(m_data, m_length); return m_hash; }
unsigned existingHash() const { ASSERT(m_hash); return m_hash; }
inline static unsigned computeHash(const UChar* data, unsigned length) { return WTF::stringHash(data, length); }
inline static unsigned computeHash(const char* data) { return WTF::stringHash(data); }
+ StringImpl* ref() { m_refCountAndFlags += s_refCountIncrement; return this; }
+ ALWAYS_INLINE void deref() { m_refCountAndFlags -= s_refCountIncrement; if (!(m_refCountAndFlags & s_refCountMask)) delete this; }
+ ALWAYS_INLINE bool hasOneRef() const { return (m_refCountAndFlags & s_refCountMask) == s_refCountIncrement; }
+
// Returns a StringImpl suitable for use on another thread.
PassRefPtr<StringImpl> crossThreadString();
// Makes a deep copy. Helpful only if you need to use a String on another thread
@@ -175,13 +179,9 @@ public:
operator NSString*();
#endif
- void operator delete(void*);
-
private:
- // Allocation from a custom buffer is only allowed internally to avoid
- // mismatched allocators. Callers should use create().
- void* operator new(size_t size);
- void* operator new(size_t size, void* address);
+ using Noncopyable::operator new;
+ void* operator new(size_t, void* inPlace) { ASSERT(inPlace); return inPlace; }
static PassRefPtr<StringImpl> createStrippingNullCharactersSlowCase(const UChar*, unsigned length);
@@ -189,15 +189,16 @@ private:
// In this case, the m_data pointer is an "internal buffer", and does not need to be deallocated.
bool bufferIsInternal() { return m_data == reinterpret_cast<const UChar*>(this + 1); }
- enum StringImplFlags {
- HasTerminatingNullCharacter,
- InTable,
- };
+ static const unsigned s_refCountMask = 0xFFFFFFFC;
+ static const unsigned s_refCountIncrement = 0x4;
+ static const unsigned s_refCountFlagHasTerminatingNullCharacter = 0x2;
+ static const unsigned s_refCountFlagInTable = 0x1;
const UChar* m_data;
+ SharedUChar* m_sharedBuffer;
unsigned m_length;
+ unsigned m_refCountAndFlags;
mutable unsigned m_hash;
- PtrAndFlags<SharedUChar, StringImplFlags> m_sharedBufferAndFlags;
// There is a fictitious variable-length UChar array at the end, which is used
// as the internal buffer by the createUninitialized and create methods.
};
diff --git a/WebCore/storage/OriginUsageRecord.cpp b/WebCore/storage/OriginUsageRecord.cpp
index 684df53..8128a1b 100644
--- a/WebCore/storage/OriginUsageRecord.cpp
+++ b/WebCore/storage/OriginUsageRecord.cpp
@@ -42,8 +42,8 @@ OriginUsageRecord::OriginUsageRecord()
void OriginUsageRecord::addDatabase(const String& identifier, const String& fullPath)
{
ASSERT(!m_databaseMap.contains(identifier));
- ASSERT_ARG(identifier, identifier.impl()->refCount() == 1);
- ASSERT_ARG(fullPath, fullPath.impl()->refCount() == 1);
+ ASSERT_ARG(identifier, identifier.impl()->hasOneRef());
+ ASSERT_ARG(fullPath, fullPath.impl()->hasOneRef());
m_databaseMap.set(identifier, DatabaseEntry(fullPath));
m_unknownSet.add(identifier);
@@ -63,7 +63,7 @@ void OriginUsageRecord::removeDatabase(const String& identifier)
void OriginUsageRecord::markDatabase(const String& identifier)
{
ASSERT(m_databaseMap.contains(identifier));
- ASSERT_ARG(identifier, identifier.impl()->refCount() == 1);
+ ASSERT_ARG(identifier, identifier.impl()->hasOneRef());
m_unknownSet.add(identifier);
m_cachedDiskUsageIsValid = false;
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list