diff options
Diffstat (limited to 'JavaScriptCore/wtf')
-rw-r--r-- | JavaScriptCore/wtf/Assertions.cpp | 7 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Noncopyable.h | 29 | ||||
-rw-r--r-- | JavaScriptCore/wtf/PassRefPtr.h | 4 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Platform.h | 6 | ||||
-rw-r--r-- | JavaScriptCore/wtf/RefCounted.h | 4 | ||||
-rw-r--r-- | JavaScriptCore/wtf/StringHashFunctions.h | 227 | ||||
-rw-r--r-- | JavaScriptCore/wtf/ThreadingPthreads.cpp | 8 | ||||
-rw-r--r-- | JavaScriptCore/wtf/gobject/GOwnPtr.cpp | 4 | ||||
-rw-r--r-- | JavaScriptCore/wtf/gobject/GOwnPtr.h | 5 | ||||
-rw-r--r-- | JavaScriptCore/wtf/gobject/GRefPtr.cpp | 4 | ||||
-rw-r--r-- | JavaScriptCore/wtf/gobject/GRefPtr.h | 4 | ||||
-rw-r--r-- | JavaScriptCore/wtf/text/AtomicString.cpp | 5 | ||||
-rw-r--r-- | JavaScriptCore/wtf/text/AtomicString.h | 4 | ||||
-rw-r--r-- | JavaScriptCore/wtf/text/StringImpl.h | 6 | ||||
-rw-r--r-- | JavaScriptCore/wtf/unicode/UTF8.cpp | 2 | ||||
-rw-r--r-- | JavaScriptCore/wtf/unicode/qt4/UnicodeQt4.h | 2 |
16 files changed, 183 insertions, 138 deletions
diff --git a/JavaScriptCore/wtf/Assertions.cpp b/JavaScriptCore/wtf/Assertions.cpp index 273e0e0..9222c1d 100644 --- a/JavaScriptCore/wtf/Assertions.cpp +++ b/JavaScriptCore/wtf/Assertions.cpp @@ -42,12 +42,11 @@ #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0500 #endif -#include <windows.h> #include <crtdbg.h> #endif -#if OS(WINCE) -#include <winbase.h> +#if OS(WINDOWS) +#include <windows.h> #endif #if PLATFORM(BREWMP) @@ -113,7 +112,7 @@ static void vprintf_stderr_common(const char* format, va_list args) printLog(buffer); } -#elif COMPILER(MSVC) && !defined(WINCEBASIC) +#elif HAVE(ISDEBUGGERPRESENT) if (IsDebuggerPresent()) { size_t size = 1024; diff --git a/JavaScriptCore/wtf/Noncopyable.h b/JavaScriptCore/wtf/Noncopyable.h index 60a46e2..898c1ba 100644 --- a/JavaScriptCore/wtf/Noncopyable.h +++ b/JavaScriptCore/wtf/Noncopyable.h @@ -21,6 +21,26 @@ #ifndef WTF_Noncopyable_h #define WTF_Noncopyable_h +#ifndef __has_feature + #define __has_feature(x) 0 +#endif + +#if __has_feature(cxx_deleted_functions) + #define WTF_MAKE_NONCOPYABLE(ClassName) \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") \ + _Pragma("clang diagnostic ignored \"-Wc++0x-extensions\"") \ + private: \ + ClassName(const ClassName&) = delete; \ + ClassName& operator=(const ClassName&) = delete; \ + _Pragma("clang diagnostic pop") +#else + #define WTF_MAKE_NONCOPYABLE(ClassName) \ + private: \ + ClassName(const ClassName&); \ + ClassName& operator=(const ClassName&) +#endif + // We don't want argument-dependent lookup to pull in everything from the WTF // namespace when you use Noncopyable, so put it in its own namespace. @@ -36,17 +56,8 @@ namespace WTFNoncopyable { ~Noncopyable() { } }; - class NoncopyableCustomAllocated { - NoncopyableCustomAllocated(const NoncopyableCustomAllocated&); - NoncopyableCustomAllocated& operator=(const NoncopyableCustomAllocated&); - protected: - NoncopyableCustomAllocated() { } - ~NoncopyableCustomAllocated() { } - }; - } // namespace WTFNoncopyable using WTFNoncopyable::Noncopyable; -using WTFNoncopyable::NoncopyableCustomAllocated; #endif // WTF_Noncopyable_h diff --git a/JavaScriptCore/wtf/PassRefPtr.h b/JavaScriptCore/wtf/PassRefPtr.h index b43c5ba..052d6e2 100644 --- a/JavaScriptCore/wtf/PassRefPtr.h +++ b/JavaScriptCore/wtf/PassRefPtr.h @@ -48,13 +48,13 @@ namespace WTF { template<typename T> REF_DEREF_INLINE void refIfNotNull(T* ptr) { - if (UNLIKELY(ptr != 0)) + if (LIKELY(ptr != 0)) ptr->ref(); } template<typename T> REF_DEREF_INLINE void derefIfNotNull(T* ptr) { - if (UNLIKELY(ptr != 0)) + if (LIKELY(ptr != 0)) ptr->deref(); } diff --git a/JavaScriptCore/wtf/Platform.h b/JavaScriptCore/wtf/Platform.h index 30bc795..1843bea 100644 --- a/JavaScriptCore/wtf/Platform.h +++ b/JavaScriptCore/wtf/Platform.h @@ -746,6 +746,7 @@ #else #define HAVE_SYS_TIMEB_H 1 #define HAVE_ALIGNED_MALLOC 1 +#define HAVE_ISDEBUGGERPRESENT 1 #endif #define HAVE_VIRTUALALLOC 1 @@ -964,7 +965,8 @@ /* The JIT is enabled by default on all x86, x64-64, ARM & MIPS platforms. */ #if !defined(ENABLE_JIT) \ && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(MIPS)) \ - && (OS(DARWIN) || !COMPILER(GCC) || GCC_VERSION_AT_LEAST(4,1,0)) + && (OS(DARWIN) || !COMPILER(GCC) || GCC_VERSION_AT_LEAST(4,1,0)) \ + && !OS(WINCE) #define ENABLE_JIT 1 #endif @@ -1142,7 +1144,7 @@ #define ENABLE_BRANCH_COMPACTION 1 #endif -#if PLATFORM(GTK) || (PLATFORM(EFL) && ENABLE(GLIB_SUPPORT)) +#if ENABLE(GLIB_SUPPORT) #include "GTypedefs.h" #endif diff --git a/JavaScriptCore/wtf/RefCounted.h b/JavaScriptCore/wtf/RefCounted.h index d85c47e..8d8b302 100644 --- a/JavaScriptCore/wtf/RefCounted.h +++ b/JavaScriptCore/wtf/RefCounted.h @@ -145,7 +145,9 @@ protected: } }; -template<typename T> class RefCountedCustomAllocated : public RefCountedBase, public NoncopyableCustomAllocated { +template<typename T> class RefCountedCustomAllocated : public RefCountedBase { + WTF_MAKE_NONCOPYABLE(RefCountedCustomAllocated); + public: void deref() { diff --git a/JavaScriptCore/wtf/StringHashFunctions.h b/JavaScriptCore/wtf/StringHashFunctions.h index 07f117f..3ad7701 100644 --- a/JavaScriptCore/wtf/StringHashFunctions.h +++ b/JavaScriptCore/wtf/StringHashFunctions.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2005, 2006, 2008, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,130 +28,142 @@ namespace WTF { // Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's static const unsigned stringHashingStartValue = 0x9e3779b9U; -// stringHash methods based on Paul Hsieh's SuperFastHash. +// Paul Hsieh's SuperFastHash // http://www.azillionmonkeys.com/qed/hash.html // char* data is interpreted as latin-encoded (zero extended to 16 bits). +class StringHasher { +public: + inline StringHasher() + : m_hash(stringHashingStartValue) + , m_hasPendingCharacter(false) + , m_pendingCharacter(0) + { + } -inline unsigned stringHash(const UChar* data, unsigned length) -{ - unsigned hash = WTF::stringHashingStartValue; - unsigned rem = length & 1; - length >>= 1; - - // Main loop - for (; length > 0; length--) { - hash += data[0]; - unsigned tmp = (data[1] << 11) ^ hash; - hash = (hash << 16) ^ tmp; - data += 2; - hash += hash >> 11; + inline void addCharacters(UChar a, UChar b) + { + ASSERT(!m_hasPendingCharacter); + addCharactersToHash(a, b); } - // Handle end case - if (rem) { - hash += data[0]; - hash ^= hash << 11; - hash += hash >> 17; + inline void addCharacter(UChar ch) + { + if (m_hasPendingCharacter) { + addCharactersToHash(m_pendingCharacter, ch); + m_hasPendingCharacter = false; + return; + } + + m_pendingCharacter = ch; + m_hasPendingCharacter = true; } - // Force "avalanching" of final 127 bits - hash ^= hash << 3; - hash += hash >> 5; - hash ^= hash << 2; - hash += hash >> 15; - hash ^= hash << 10; - - hash &= 0x7fffffff; - - // this avoids ever returning a hash code of 0, since that is used to - // signal "hash not computed yet", using a value that is likely to be - // effectively the same as 0 when the low bits are masked - if (hash == 0) - hash = 0x40000000; - - return hash; -} - -inline unsigned stringHash(const char* data, unsigned length) -{ - unsigned hash = WTF::stringHashingStartValue; - unsigned rem = length & 1; - length >>= 1; - - // Main loop - for (; length > 0; length--) { - hash += static_cast<unsigned char>(data[0]); - unsigned tmp = (static_cast<unsigned char>(data[1]) << 11) ^ hash; - hash = (hash << 16) ^ tmp; - data += 2; - hash += hash >> 11; + inline unsigned hash() const + { + unsigned result = m_hash; + + // Handle end case. + if (m_hasPendingCharacter) { + result += m_pendingCharacter; + result ^= result << 11; + result += result >> 17; + } + + // Force "avalanching" of final 31 bits. + result ^= result << 3; + result += result >> 5; + result ^= result << 2; + result += result >> 15; + result ^= result << 10; + + // First bit is used in UStringImpl for m_isIdentifier. + result &= 0x7fffffff; + + // This avoids ever returning a hash code of 0, since that is used to + // signal "hash not computed yet", using a value that is likely to be + // effectively the same as 0 when the low bits are masked. + if (!result) + return 0x40000000; + + return result; } - // Handle end case - if (rem) { - hash += static_cast<unsigned char>(data[0]); - hash ^= hash << 11; - hash += hash >> 17; + template<typename T, UChar Converter(T)> static inline unsigned createHash(const T* data, unsigned length) + { + StringHasher hasher; + bool rem = length & 1; + length >>= 1; + + while (length--) { + hasher.addCharacters(Converter(data[0]), Converter(data[1])); + data += 2; + } + + if (rem) + hasher.addCharacter(Converter(*data)); + + return hasher.hash(); } - // Force "avalanching" of final 127 bits - hash ^= hash << 3; - hash += hash >> 5; - hash ^= hash << 2; - hash += hash >> 15; - hash ^= hash << 10; - - hash &= 0x7fffffff; - - // this avoids ever returning a hash code of 0, since that is used to - // signal "hash not computed yet", using a value that is likely to be - // effectively the same as 0 when the low bits are masked - if (hash == 0) - hash = 0x40000000; - - return hash; -} - -inline unsigned stringHash(const char* data) -{ - unsigned hash = WTF::stringHashingStartValue; - - // Main loop - for (;;) { - unsigned char b0 = data[0]; - if (!b0) - break; - unsigned char b1 = data[1]; - if (!b1) { - hash += b0; - hash ^= hash << 11; - hash += hash >> 17; - break; + template<typename T, UChar Converter(T)> static inline unsigned createHash(const T* data) + { + StringHasher hasher; + + while (true) { + UChar b0 = Converter(*data++); + if (!b0) + break; + UChar b1 = Converter(*data++); + if (!b1) { + hasher.addCharacter(b0); + break; + } + + hasher.addCharacters(b0, b1); } - hash += b0; - unsigned tmp = (b1 << 11) ^ hash; - hash = (hash << 16) ^ tmp; - data += 2; - hash += hash >> 11; + + return hasher.hash(); + } + + template<typename T> static inline unsigned createHash(const T* data, unsigned length) + { + return createHash<T, defaultCoverter>(data, length); } - // Force "avalanching" of final 127 bits. - hash ^= hash << 3; - hash += hash >> 5; - hash ^= hash << 2; - hash += hash >> 15; - hash ^= hash << 10; + template<typename T> static inline unsigned createHash(const T* data) + { + return createHash<T, defaultCoverter>(data); + } - hash &= 0x7fffffff; + template<size_t length> static inline unsigned createBlobHash(const void* data) + { + COMPILE_ASSERT(!(length % 4), length_must_be_a_multible_of_four); + return createHash<UChar>(static_cast<const UChar*>(data), length / sizeof(UChar)); + } - // This avoids ever returning a hash code of 0, since that is used to - // signal "hash not computed yet", using a value that is likely to be - // effectively the same as 0 when the low bits are masked. - if (hash == 0) - hash = 0x40000000; +private: + static inline UChar defaultCoverter(UChar ch) + { + return ch; + } + + static inline UChar defaultCoverter(char ch) + { + return static_cast<unsigned char>(ch); + } + + inline void addCharactersToHash(UChar a, UChar b) + { + m_hash += a; + unsigned tmp = (b << 11) ^ m_hash; + m_hash = (m_hash << 16) ^ tmp; + m_hash += m_hash >> 11; + } - return hash; -} + unsigned m_hash; + bool m_hasPendingCharacter; + UChar m_pendingCharacter; +}; } // namespace WTF diff --git a/JavaScriptCore/wtf/ThreadingPthreads.cpp b/JavaScriptCore/wtf/ThreadingPthreads.cpp index 98286d3..0017a6f 100644 --- a/JavaScriptCore/wtf/ThreadingPthreads.cpp +++ b/JavaScriptCore/wtf/ThreadingPthreads.cpp @@ -241,12 +241,6 @@ ThreadIdentifier currentThread() Mutex::Mutex() { -#if PTHREAD_MUTEX_NORMAL == PTHREAD_MUTEX_DEFAULT - - pthread_mutex_init(&m_mutex, 0); - -#else - pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); @@ -254,8 +248,6 @@ Mutex::Mutex() pthread_mutex_init(&m_mutex, &attr); pthread_mutexattr_destroy(&attr); - -#endif } Mutex::~Mutex() diff --git a/JavaScriptCore/wtf/gobject/GOwnPtr.cpp b/JavaScriptCore/wtf/gobject/GOwnPtr.cpp index da0d839..8dcfb9e 100644 --- a/JavaScriptCore/wtf/gobject/GOwnPtr.cpp +++ b/JavaScriptCore/wtf/gobject/GOwnPtr.cpp @@ -19,6 +19,8 @@ #include "config.h" #include "GOwnPtr.h" +#if ENABLE(GLIB_SUPPORT) + #include <gio/gio.h> #include <glib.h> @@ -65,3 +67,5 @@ template <> void freeOwnedGPtr<GFile>(GFile* ptr) g_object_unref(ptr); } } // namespace WTF + +#endif // ENABLE(GLIB_SUPPORT) diff --git a/JavaScriptCore/wtf/gobject/GOwnPtr.h b/JavaScriptCore/wtf/gobject/GOwnPtr.h index e04ee9d..cec3e43 100644 --- a/JavaScriptCore/wtf/gobject/GOwnPtr.h +++ b/JavaScriptCore/wtf/gobject/GOwnPtr.h @@ -22,6 +22,8 @@ #ifndef GOwnPtr_h #define GOwnPtr_h +#if ENABLE(GLIB_SUPPORT) + #include <algorithm> #include <wtf/Assertions.h> #include <wtf/Noncopyable.h> @@ -135,4 +137,7 @@ template <typename T> inline void freeOwnedGPtr(T* ptr) using WTF::GOwnPtr; +#endif // ENABLE(GLIB_SUPPORT) + #endif // GOwnPtr_h + diff --git a/JavaScriptCore/wtf/gobject/GRefPtr.cpp b/JavaScriptCore/wtf/gobject/GRefPtr.cpp index 14f7cf4..085684e 100644 --- a/JavaScriptCore/wtf/gobject/GRefPtr.cpp +++ b/JavaScriptCore/wtf/gobject/GRefPtr.cpp @@ -19,6 +19,8 @@ #include "config.h" #include "GRefPtr.h" +#if ENABLE(GLIB_SUPPORT) + #include <glib.h> namespace WTF { @@ -80,3 +82,5 @@ template <> void derefPlatformPtr(GSource* ptr) } } // namespace WTF + +#endif // ENABLE(GLIB_SUPPORT) diff --git a/JavaScriptCore/wtf/gobject/GRefPtr.h b/JavaScriptCore/wtf/gobject/GRefPtr.h index ede0a7a..4efd9be 100644 --- a/JavaScriptCore/wtf/gobject/GRefPtr.h +++ b/JavaScriptCore/wtf/gobject/GRefPtr.h @@ -23,6 +23,8 @@ #ifndef WTF_GRefPtr_h #define WTF_GRefPtr_h +#if ENABLE(GLIB_SUPPORT) + #include "AlwaysInline.h" #include "PlatformRefPtr.h" #include <algorithm> @@ -54,4 +56,6 @@ template <typename T> inline void derefPlatformPtr(T* ptr) } // namespace WTF +#endif // ENABLE(GLIB_SUPPORT) + #endif // WTF_GRefPtr_h diff --git a/JavaScriptCore/wtf/text/AtomicString.cpp b/JavaScriptCore/wtf/text/AtomicString.cpp index 1981170..c8140d6 100644 --- a/JavaScriptCore/wtf/text/AtomicString.cpp +++ b/JavaScriptCore/wtf/text/AtomicString.cpp @@ -156,6 +156,11 @@ static inline bool equal(StringImpl* string, const UChar* characters, unsigned l #endif } +bool operator==(const AtomicString& string, const Vector<UChar>& vector) +{ + return string.impl() && equal(string.impl(), vector.data(), vector.size()); +} + struct UCharBufferTranslator { static unsigned hash(const UCharBuffer& buf) { diff --git a/JavaScriptCore/wtf/text/AtomicString.h b/JavaScriptCore/wtf/text/AtomicString.h index cfabde7..06e63f4 100644 --- a/JavaScriptCore/wtf/text/AtomicString.h +++ b/JavaScriptCore/wtf/text/AtomicString.h @@ -126,15 +126,19 @@ private: inline bool operator==(const AtomicString& a, const AtomicString& b) { return a.impl() == b.impl(); } bool operator==(const AtomicString& a, const char* b); +bool operator==(const AtomicString& a, const Vector<UChar>& b); inline bool operator==(const AtomicString& a, const String& b) { return equal(a.impl(), b.impl()); } inline bool operator==(const char* a, const AtomicString& b) { return b == a; } inline bool operator==(const String& a, const AtomicString& b) { return equal(a.impl(), b.impl()); } +inline bool operator==(const Vector<UChar>& a, const AtomicString& b) { return b == a; } inline bool operator!=(const AtomicString& a, const AtomicString& b) { return a.impl() != b.impl(); } inline bool operator!=(const AtomicString& a, const char *b) { return !(a == b); } inline bool operator!=(const AtomicString& a, const String& b) { return !equal(a.impl(), b.impl()); } +inline bool operator!=(const AtomicString& a, const Vector<UChar>& b) { return !(a == b); } inline bool operator!=(const char* a, const AtomicString& b) { return !(b == a); } inline bool operator!=(const String& a, const AtomicString& b) { return !equal(a.impl(), b.impl()); } +inline bool operator!=(const Vector<UChar>& a, const AtomicString& b) { return !(a == b); } inline bool equalIgnoringCase(const AtomicString& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); } inline bool equalIgnoringCase(const AtomicString& a, const char* b) { return equalIgnoringCase(a.impl(), b); } diff --git a/JavaScriptCore/wtf/text/StringImpl.h b/JavaScriptCore/wtf/text/StringImpl.h index cec0b80..7025d9f 100644 --- a/JavaScriptCore/wtf/text/StringImpl.h +++ b/JavaScriptCore/wtf/text/StringImpl.h @@ -233,9 +233,9 @@ public: unsigned hash() const { if (!m_hash) m_hash = computeHash(m_data, m_length); return m_hash; } unsigned existingHash() const { ASSERT(m_hash); return m_hash; } - static unsigned computeHash(const UChar* data, unsigned length) { return WTF::stringHash(data, length); } - static unsigned computeHash(const char* data, unsigned length) { return WTF::stringHash(data, length); } - static unsigned computeHash(const char* data) { return WTF::stringHash(data); } + static unsigned computeHash(const UChar* data, unsigned length) { return WTF::StringHasher::createHash<UChar>(data, length); } + static unsigned computeHash(const char* data, unsigned length) { return WTF::StringHasher::createHash<char>(data, length); } + static unsigned computeHash(const char* data) { return WTF::StringHasher::createHash<char>(data); } ALWAYS_INLINE void deref() { m_refCountAndFlags -= s_refCountIncrement; if (!(m_refCountAndFlags & (s_refCountMask | s_refCountFlagStatic))) delete this; } ALWAYS_INLINE bool hasOneRef() const { return (m_refCountAndFlags & (s_refCountMask | s_refCountFlagStatic)) == s_refCountIncrement; } diff --git a/JavaScriptCore/wtf/unicode/UTF8.cpp b/JavaScriptCore/wtf/unicode/UTF8.cpp index 21d5856..40c5609 100644 --- a/JavaScriptCore/wtf/unicode/UTF8.cpp +++ b/JavaScriptCore/wtf/unicode/UTF8.cpp @@ -240,7 +240,7 @@ ConversionResult convertUTF8ToUTF16( UChar* target = *targetStart; while (source < sourceEnd) { UChar32 ch = 0; - int extraBytesToRead = UTF8SequenceLength(*source) - 1; + int extraBytesToRead = inlineUTF8SequenceLength(*source) - 1; if (source + extraBytesToRead >= sourceEnd) { result = sourceExhausted; break; diff --git a/JavaScriptCore/wtf/unicode/qt4/UnicodeQt4.h b/JavaScriptCore/wtf/unicode/qt4/UnicodeQt4.h index c9e2e1c..547ed32 100644 --- a/JavaScriptCore/wtf/unicode/qt4/UnicodeQt4.h +++ b/JavaScriptCore/wtf/unicode/qt4/UnicodeQt4.h @@ -58,7 +58,7 @@ namespace QUnicodeTables { QT_END_NAMESPACE // ugly hack to make UChar compatible with JSChar in API/JSStringRef.h -#if defined(Q_OS_WIN) || COMPILER(WINSCW) || (COMPILER(RVCT) && OS(SYMBIAN)) +#if defined(Q_OS_WIN) || COMPILER(WINSCW) || (COMPILER(RVCT) && !OS(LINUX)) typedef wchar_t UChar; #else typedef uint16_t UChar; |