diff options
author | Steve Block <steveblock@google.com> | 2010-02-15 12:23:52 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-02-16 11:48:32 +0000 |
commit | 8a0914b749bbe7da7768e07a7db5c6d4bb09472b (patch) | |
tree | 73f9065f370435d6fde32ae129d458a8c77c8dff /JavaScriptCore/wtf | |
parent | bf14be70295513b8076f3fa47a268a7e42b2c478 (diff) | |
download | external_webkit-8a0914b749bbe7da7768e07a7db5c6d4bb09472b.zip external_webkit-8a0914b749bbe7da7768e07a7db5c6d4bb09472b.tar.gz external_webkit-8a0914b749bbe7da7768e07a7db5c6d4bb09472b.tar.bz2 |
Merge webkit.org at r54731 : Initial merge by git
Change-Id: Ia79977b6cf3b0b00c06ef39419989b28e57e4f4a
Diffstat (limited to 'JavaScriptCore/wtf')
-rw-r--r-- | JavaScriptCore/wtf/Complex.h | 46 | ||||
-rw-r--r-- | JavaScriptCore/wtf/FastMalloc.cpp | 20 | ||||
-rw-r--r-- | JavaScriptCore/wtf/HashTable.h | 3 | ||||
-rw-r--r-- | JavaScriptCore/wtf/HashTraits.h | 21 | ||||
-rw-r--r-- | JavaScriptCore/wtf/MathExtras.h | 11 | ||||
-rw-r--r-- | JavaScriptCore/wtf/PassRefPtr.h | 45 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Platform.h | 16 | ||||
-rw-r--r-- | JavaScriptCore/wtf/RefPtr.h | 47 | ||||
-rw-r--r-- | JavaScriptCore/wtf/ValueCheck.h | 64 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Vector.h | 21 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Vector3.h | 138 | ||||
-rw-r--r-- | JavaScriptCore/wtf/unicode/qt4/UnicodeQt4.h | 2 |
12 files changed, 357 insertions, 77 deletions
diff --git a/JavaScriptCore/wtf/Complex.h b/JavaScriptCore/wtf/Complex.h new file mode 100644 index 0000000..cfd1d20 --- /dev/null +++ b/JavaScriptCore/wtf/Complex.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef Complex_h +#define Complex_h + +#include <complex> +#include <wtf/MathExtras.h> + +namespace WebCore { + +typedef std::complex<double> Complex; + +inline Complex complexFromMagnitudePhase(double magnitude, double phase) +{ + return Complex(magnitude * cos(phase), magnitude * sin(phase)); +} + +} // namespace WebCore + +#endif // Complex_h diff --git a/JavaScriptCore/wtf/FastMalloc.cpp b/JavaScriptCore/wtf/FastMalloc.cpp index 7b14809..79d2bfb 100644 --- a/JavaScriptCore/wtf/FastMalloc.cpp +++ b/JavaScriptCore/wtf/FastMalloc.cpp @@ -239,8 +239,16 @@ void* fastMalloc(size_t n) void* result = malloc(n); #endif - if (!result) + if (!result) { +#if PLATFORM(BREWMP) + // The behavior of malloc(0) is implementation defined. + // To make sure that fastMalloc never returns 0, retry with fastMalloc(1). + if (!n) + return fastMalloc(1); +#endif CRASH(); + } + return result; } @@ -279,8 +287,16 @@ void* fastCalloc(size_t n_elements, size_t element_size) void* result = calloc(n_elements, element_size); #endif - if (!result) + if (!result) { +#if PLATFORM(BREWMP) + // If either n_elements or element_size is 0, the behavior of calloc is implementation defined. + // To make sure that fastCalloc never returns 0, retry with fastCalloc(1, 1). + if (!n_elements || !element_size) + return fastCalloc(1, 1); +#endif CRASH(); + } + return result; } diff --git a/JavaScriptCore/wtf/HashTable.h b/JavaScriptCore/wtf/HashTable.h index f1473e3..ceb8963 100644 --- a/JavaScriptCore/wtf/HashTable.h +++ b/JavaScriptCore/wtf/HashTable.h @@ -24,6 +24,7 @@ #include "FastMalloc.h" #include "HashTraits.h" +#include "ValueCheck.h" #include <wtf/Assertions.h> #include <wtf/Threading.h> @@ -1021,7 +1022,7 @@ namespace WTF { ASSERT(entry == it.m_position); ++count; - KeyTraits::checkValueConsistency(it->first); + ValueCheck<Key>::checkConsistency(it->first); } ASSERT(count == m_keyCount); diff --git a/JavaScriptCore/wtf/HashTraits.h b/JavaScriptCore/wtf/HashTraits.h index 96ecac9..c8d40f7 100644 --- a/JavaScriptCore/wtf/HashTraits.h +++ b/JavaScriptCore/wtf/HashTraits.h @@ -26,13 +26,6 @@ #include <utility> #include <limits> -// For malloc_size and _msize. -#if OS(DARWIN) -#include <malloc/malloc.h> -#elif COMPILER(MSVC) -#include <malloc.h> -#endif - namespace WTF { using std::pair; @@ -58,7 +51,6 @@ namespace WTF { template<typename T> struct GenericHashTraits : GenericHashTraitsBase<IsInteger<T>::value, T> { typedef T TraitType; static T emptyValue() { return T(); } - static void checkValueConsistency(const T&) { } }; template<typename T> struct HashTraits : GenericHashTraits<T> { }; @@ -87,19 +79,6 @@ namespace WTF { static const bool needsDestruction = false; static void constructDeletedValue(P*& slot) { slot = reinterpret_cast<P*>(-1); } static bool isDeletedValue(P* value) { return value == reinterpret_cast<P*>(-1); } -#if !ASSERT_DISABLED - static void checkValueConsistency(const P* p) - { -#if (defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC) || !defined(NDEBUG) -#if OS(DARWIN) - ASSERT(malloc_size(p)); -#elif COMPILER(MSVC) - ASSERT(_msize(const_cast<P*>(p))); -#endif -#endif - HashTraits<P>::checkValueConsistency(*p); - } -#endif }; template<typename P> struct HashTraits<RefPtr<P> > : GenericHashTraits<RefPtr<P> > { diff --git a/JavaScriptCore/wtf/MathExtras.h b/JavaScriptCore/wtf/MathExtras.h index a18949e..8666724 100644 --- a/JavaScriptCore/wtf/MathExtras.h +++ b/JavaScriptCore/wtf/MathExtras.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +26,8 @@ #ifndef WTF_MathExtras_h #define WTF_MathExtras_h +#include <cmath> #include <float.h> -#include <math.h> #include <stdlib.h> #if OS(SOLARIS) @@ -186,4 +186,11 @@ inline float deg2turn(float d) { return d / 360.0f; } inline float rad2grad(float r) { return r * 200.0f / piFloat; } inline float grad2rad(float g) { return g * piFloat / 200.0f; } +#if !COMPILER(MSVC) && !COMPILER(RVCT) && !OS(ANDROID) && !COMPILER(WINSCW) +using std::isfinite; +using std::isinf; +using std::isnan; +using std::signbit; +#endif + #endif // #ifndef WTF_MathExtras_h diff --git a/JavaScriptCore/wtf/PassRefPtr.h b/JavaScriptCore/wtf/PassRefPtr.h index 36ba78e..9c6e44f 100644 --- a/JavaScriptCore/wtf/PassRefPtr.h +++ b/JavaScriptCore/wtf/PassRefPtr.h @@ -28,10 +28,21 @@ namespace WTF { template<typename T> class RefPtr; template<typename T> class PassRefPtr; template <typename T> PassRefPtr<T> adoptRef(T*); - - // Remove inline for winscw compiler to prevent the compiler agressively resolving - // T::deref(), which will fail compiling when PassRefPtr<T> is used as class member - // or function arguments before T is defined. + + + // Remove inline for WINSCW compiler to prevent the compiler agressively resolving + // T::ref() and T::deref(), which will fail compiling when PassRefPtr<T> is used as + // a class member or function arguments before T is defined. + template<typename T> +#if !COMPILER(WINSCW) + inline +#endif + void refIfNotNull(T* ptr) + { + if (UNLIKELY(ptr != 0)) + ptr->ref(); + } + template<typename T> #if !COMPILER(WINSCW) inline @@ -45,7 +56,7 @@ namespace WTF { template<typename T> class PassRefPtr { public: PassRefPtr() : m_ptr(0) {} - PassRefPtr(T* ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); } + PassRefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } // It somewhat breaks the type system to allow transfer of ownership out of // a const PassRefPtr. However, it makes it much easier to work with PassRefPtr // temporaries, and we don't really have a need to use real const PassRefPtrs @@ -53,14 +64,14 @@ namespace WTF { PassRefPtr(const PassRefPtr& o) : m_ptr(o.releaseRef()) {} template <typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.releaseRef()) { } - ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull<T>(m_ptr); } + ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull(m_ptr); } template <class U> - PassRefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T* ptr = m_ptr) ptr->ref(); } + PassRefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { T* ptr = m_ptr; refIfNotNull(ptr); } T* get() const { return m_ptr; } - void clear() { if (T* ptr = m_ptr) ptr->deref(); m_ptr = 0; } + void clear() { T* ptr = m_ptr; derefIfNotNull(ptr); m_ptr = 0; } T* releaseRef() const { T* tmp = m_ptr; m_ptr = 0; return tmp; } T& operator*() const { return *m_ptr; } @@ -143,23 +154,19 @@ namespace WTF { template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const RefPtr<U>& o) { T* optr = o.get(); - if (optr) - optr->ref(); + refIfNotNull(optr); T* ptr = m_ptr; m_ptr = optr; - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(T* optr) { - if (optr) - optr->ref(); + refIfNotNull(optr); T* ptr = m_ptr; m_ptr = optr; - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } @@ -167,8 +174,7 @@ namespace WTF { { T* ptr = m_ptr; m_ptr = ref.releaseRef(); - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } @@ -176,8 +182,7 @@ namespace WTF { { T* ptr = m_ptr; m_ptr = ref.releaseRef(); - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } diff --git a/JavaScriptCore/wtf/Platform.h b/JavaScriptCore/wtf/Platform.h index d61d596..b113e79 100644 --- a/JavaScriptCore/wtf/Platform.h +++ b/JavaScriptCore/wtf/Platform.h @@ -422,6 +422,8 @@ #else #define WTF_PLATFORM_BREWMP_SIMULATOR 0 #endif +#undef WTF_OS_WINDOWS +#undef WTF_PLATFORM_WIN #elif OS(DARWIN) #define WTF_PLATFORM_MAC 1 #elif OS(WINDOWS) @@ -627,6 +629,10 @@ #define ENABLE_NETSCAPE_PLUGIN_API 0 #endif +#if PLATFORM(BREWMP) +#define USE_SYSTEM_MALLOC 1 +#endif + #if !defined(HAVE_ACCESSIBILITY) #if PLATFORM(IPHONE) || PLATFORM(MAC) || PLATFORM(WIN) || PLATFORM(GTK) || PLATFORM(CHROMIUM) #define HAVE_ACCESSIBILITY 1 @@ -889,6 +895,13 @@ on MinGW. See https://bugs.webkit.org/show_bug.cgi?id=29268 */ #endif /* !defined(ENABLE_JIT) */ +/* CPU architecture specific optimizations */ +#if CPU(ARM_TRADITIONAL) +#if ENABLE(JIT) && !defined(ENABLE_JIT_OPTIMIZE_MOD) && WTF_ARM_ARCH_AT_LEAST(5) +#define ENABLE_JIT_OPTIMIZE_MOD 1 +#endif +#endif + #if ENABLE(JIT) #ifndef ENABLE_JIT_OPTIMIZE_CALL #define ENABLE_JIT_OPTIMIZE_CALL 1 @@ -902,6 +915,9 @@ on MinGW. See https://bugs.webkit.org/show_bug.cgi?id=29268 */ #ifndef ENABLE_JIT_OPTIMIZE_METHOD_CALLS #define ENABLE_JIT_OPTIMIZE_METHOD_CALLS 1 #endif +#ifndef ENABLE_JIT_OPTIMIZE_MOD +#define ENABLE_JIT_OPTIMIZE_MOD 0 +#endif #endif #if CPU(X86) && COMPILER(MSVC) diff --git a/JavaScriptCore/wtf/RefPtr.h b/JavaScriptCore/wtf/RefPtr.h index e6d1047..84e841c 100644 --- a/JavaScriptCore/wtf/RefPtr.h +++ b/JavaScriptCore/wtf/RefPtr.h @@ -24,6 +24,7 @@ #include <algorithm> #include "AlwaysInline.h" #include "FastAllocBase.h" +#include "PassRefPtr.h" namespace WTF { @@ -37,8 +38,8 @@ namespace WTF { template <typename T> class RefPtr : public FastAllocBase { public: RefPtr() : m_ptr(0) { } - RefPtr(T* ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); } - RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { if (T* ptr = m_ptr) ptr->ref(); } + RefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } + RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { T* ptr = m_ptr; refIfNotNull(ptr); } // see comment in PassRefPtr.h for why this takes const reference template <typename U> RefPtr(const PassRefPtr<U>&); template <typename U> RefPtr(const NonNullPassRefPtr<U>&); @@ -50,13 +51,13 @@ namespace WTF { RefPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { } bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue(); } - ~RefPtr() { if (T* ptr = m_ptr) ptr->deref(); } + ~RefPtr() { derefIfNotNull(m_ptr); } - template <typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T* ptr = m_ptr) ptr->ref(); } + template <typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { T* ptr = m_ptr; refIfNotNull(ptr); } T* get() const { return m_ptr; } - void clear() { if (T* ptr = m_ptr) ptr->deref(); m_ptr = 0; } + void clear() { derefIfNotNull(m_ptr); m_ptr = 0; } PassRefPtr<T> release() { PassRefPtr<T> tmp = adoptRef(m_ptr); m_ptr = 0; return tmp; } T& operator*() const { return *m_ptr; } @@ -65,12 +66,8 @@ namespace WTF { bool operator!() const { return !m_ptr; } // This conversion operator allows implicit conversion to bool but not to other integer types. -#if COMPILER(WINSCW) - operator bool() const { return m_ptr; } -#else - typedef T* RefPtr::*UnspecifiedBoolType; + typedef T* (RefPtr::*UnspecifiedBoolType); operator UnspecifiedBoolType() const { return m_ptr ? &RefPtr::m_ptr : 0; } -#endif RefPtr& operator=(const RefPtr&); RefPtr& operator=(T*); @@ -101,35 +98,29 @@ namespace WTF { template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o) { T* optr = o.get(); - if (optr) - optr->ref(); + refIfNotNull(optr); T* ptr = m_ptr; m_ptr = optr; - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o) { T* optr = o.get(); - if (optr) - optr->ref(); + refIfNotNull(optr); T* ptr = m_ptr; m_ptr = optr; - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr) { - if (optr) - optr->ref(); + refIfNotNull(optr); T* ptr = m_ptr; m_ptr = optr; - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } @@ -137,8 +128,7 @@ namespace WTF { { T* ptr = m_ptr; m_ptr = o.releaseRef(); - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } @@ -146,8 +136,7 @@ namespace WTF { { T* ptr = m_ptr; m_ptr = o.releaseRef(); - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } @@ -155,8 +144,7 @@ namespace WTF { { T* ptr = m_ptr; m_ptr = o.releaseRef(); - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } @@ -164,8 +152,7 @@ namespace WTF { { T* ptr = m_ptr; m_ptr = o.releaseRef(); - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } diff --git a/JavaScriptCore/wtf/ValueCheck.h b/JavaScriptCore/wtf/ValueCheck.h new file mode 100644 index 0000000..cd321b8 --- /dev/null +++ b/JavaScriptCore/wtf/ValueCheck.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ValueCheck_h +#define ValueCheck_h + +// For malloc_size and _msize. +#if OS(DARWIN) +#include <malloc/malloc.h> +#elif COMPILER(MSVC) +#include <malloc.h> +#endif + +namespace WTF { + +template<typename T> struct ValueCheck { + typedef T TraitType; + static void checkConsistency(const T&) { } +}; + +#if !ASSERT_DISABLED +template<typename P> struct ValueCheck<P*> { + typedef P* TraitType; + static void checkConsistency(const P* p) + { + if (!p) + return; +#if (defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC) || !defined(NDEBUG) +#if OS(DARWIN) + ASSERT(malloc_size(p)); +#elif COMPILER(MSVC) + ASSERT(_msize(const_cast<P*>(p))); +#endif +#endif + ValueCheck<P>::checkConsistency(*p); + } +}; +#endif + +} + +#endif // ValueCheck_h diff --git a/JavaScriptCore/wtf/Vector.h b/JavaScriptCore/wtf/Vector.h index decc9c9..81ea321 100644 --- a/JavaScriptCore/wtf/Vector.h +++ b/JavaScriptCore/wtf/Vector.h @@ -24,6 +24,7 @@ #include "FastAllocBase.h" #include "Noncopyable.h" #include "NotFound.h" +#include "ValueCheck.h" #include "VectorTraits.h" #include <limits> #include <utility> @@ -586,6 +587,8 @@ namespace WTF { m_buffer.swap(other.m_buffer); } + void checkConsistency(); + private: void expandCapacity(size_t newMinCapacity); const T* expandCapacity(size_t newMinCapacity, const T*); @@ -987,6 +990,15 @@ namespace WTF { } template<typename T, size_t inlineCapacity> + inline void Vector<T, inlineCapacity>::checkConsistency() + { +#if !ASSERT_DISABLED + for (size_t i = 0; i < size(); ++i) + ValueCheck<T>::checkConsistency(at(i)); +#endif + } + + template<typename T, size_t inlineCapacity> void deleteAllValues(const Vector<T, inlineCapacity>& collection) { typedef typename Vector<T, inlineCapacity>::const_iterator iterator; @@ -1016,6 +1028,15 @@ namespace WTF { return !(a == b); } +#if !ASSERT_DISABLED + template<typename T> struct ValueCheck<Vector<T> > { + typedef Vector<T> TraitType; + static void checkConsistency(const Vector<T>& v) + { + v.checkConsistency(); + } + }; +#endif } // namespace WTF diff --git a/JavaScriptCore/wtf/Vector3.h b/JavaScriptCore/wtf/Vector3.h new file mode 100644 index 0000000..3c40b61 --- /dev/null +++ b/JavaScriptCore/wtf/Vector3.h @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef Vector3_h +#define Vector3_h + +#include <math.h> + +namespace WebCore { + +class Vector3 { +public: + Vector3() + : m_x(0.0) + , m_y(0.0) + , m_z(0.0) + { + } + + Vector3(double x, double y, double z) + : m_x(x) + , m_y(y) + , m_z(z) + { + } + + Vector3(const float p[3]) + : m_x(p[0]) + , m_y(p[1]) + , m_z(p[2]) + { + } + + Vector3(const double p[3]) + : m_x(p[0]) + , m_y(p[1]) + , m_z(p[2]) + { + } + + double abs() const + { + return sqrt(m_x * m_x + m_y * m_y + m_z * m_z); + } + + bool isZero() const + { + return !m_x && !m_y && !m_z; + } + + void normalize() + { + double absValue = abs(); + if (!absValue) + return; + + double k = 1.0 / absValue; + m_x *= k; + m_y *= k; + m_z *= k; + } + + double x() const { return m_x; } + double y() const { return m_y; } + double z() const { return m_z; } + +private: + double m_x; + double m_y; + double m_z; +}; + +inline Vector3 operator+(const Vector3& v1, const Vector3& v2) +{ + return Vector3(v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z()); +} + +inline Vector3 operator-(const Vector3& v1, const Vector3& v2) +{ + return Vector3(v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z()); +} + +inline Vector3 operator*(double k, const Vector3& v) +{ + return Vector3(k * v.x(), k * v.y(), k * v.z()); +} + +inline Vector3 operator*(const Vector3& v, double k) +{ + return Vector3(k * v.x(), k * v.y(), k * v.z()); +} + +inline double dot(const Vector3& v1, const Vector3& v2) +{ + return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z(); +} + +inline Vector3 cross(const Vector3& v1, const Vector3& v2) +{ + double x3 = v1.y() * v2.z() - v1.z() * v2.y(); + double y3 = v1.z() * v2.x() - v1.x() * v2.z(); + double z3 = v1.x() * v2.y() - v1.y() * v2.x(); + return Vector3(x3, y3, z3); +} + +inline double distance(const Vector3& v1, const Vector3& v2) +{ + return (v1 - v2).abs(); +} + +} // WebCore + +#endif // Vector3_h diff --git a/JavaScriptCore/wtf/unicode/qt4/UnicodeQt4.h b/JavaScriptCore/wtf/unicode/qt4/UnicodeQt4.h index cfd482d..9b1754a 100644 --- a/JavaScriptCore/wtf/unicode/qt4/UnicodeQt4.h +++ b/JavaScriptCore/wtf/unicode/qt4/UnicodeQt4.h @@ -56,7 +56,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) +#if defined(Q_OS_WIN) || COMPILER(WINSCW) || COMPILER(RVCT) typedef wchar_t UChar; #else typedef uint16_t UChar; |