Changeset 123819 in webkit
- Timestamp:
- Jul 26, 2012 5:25:04 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/PerformanceTests/ChangeLog
r123655 r123819 1 2012-07-26 Arnaud Renevier <a.renevier@sisa.samsung.com> 2 3 constructing TypedArray from another TypedArray is slow 4 https://bugs.webkit.org/show_bug.cgi?id=90838 5 6 Reviewed by Kenneth Russell. 7 8 * Bindings/typed-array-construct-from-same-type.html: Added. 9 * Bindings/typed-array-construct-from-typed.html: Added. 10 1 11 2012-07-25 Ryosuke Niwa <rniwa@webkit.org> 2 12 -
trunk/Source/WTF/ChangeLog
r123786 r123819 1 2012-07-26 Arnaud Renevier <a.renevier@sisa.samsung.com> 2 3 constructing TypedArray from another TypedArray is slow 4 https://bugs.webkit.org/show_bug.cgi?id=90838 5 6 Reviewed by Kenneth Russell. 7 8 Introduce virtual method getType on ArrayBufferView. It returns the actual 9 type of the view. This method replaces previous is<Type>Array() methods. 10 11 * wtf/ArrayBufferView.h: 12 * wtf/Float32Array.h: 13 (WTF::Float32Array::getType): 14 (Float32Array): 15 * wtf/Float64Array.h: 16 (WTF::Float64Array::getType): 17 (Float64Array): 18 * wtf/Int16Array.h: 19 (WTF::Int16Array::getType): 20 (Int16Array): 21 * wtf/Int32Array.h: 22 (WTF::Int32Array::getType): 23 (Int32Array): 24 * wtf/Int8Array.h: 25 (WTF::Int8Array::getType): 26 (Int8Array): 27 * wtf/IntegralTypedArrayBase.h: 28 * wtf/TypedArrayBase.h: 29 (TypedArrayBase): 30 (WTF::TypedArrayBase::item): 31 * wtf/Uint16Array.h: 32 (WTF::Uint16Array::getType): 33 (Uint16Array): 34 * wtf/Uint32Array.h: 35 (WTF::Uint32Array::getType): 36 (Uint32Array): 37 * wtf/Uint8Array.h: 38 (WTF::Uint8Array::getType): 39 (Uint8Array): 40 * wtf/Uint8ClampedArray.h: 41 (WTF::Uint8ClampedArray::getType): 42 (Uint8ClampedArray): 43 1 44 2012-07-26 Zeno Albisser <zeno@webkit.org> 2 45 -
trunk/Source/WTF/wtf/ArrayBufferView.h
r112558 r123819 39 39 class WTF_EXPORT_PRIVATE_RTTI ArrayBufferView : public RefCounted<ArrayBufferView> { 40 40 public: 41 virtual bool isByteArray() const { return false; } 42 virtual bool isUnsignedByteArray() const { return false; } 43 virtual bool isUnsignedByteClampedArray() const { return false; } 44 virtual bool isShortArray() const { return false; } 45 virtual bool isUnsignedShortArray() const { return false; } 46 virtual bool isIntArray() const { return false; } 47 virtual bool isUnsignedIntArray() const { return false; } 48 virtual bool isFloatArray() const { return false; } 49 virtual bool isDoubleArray() const { return false; } 50 virtual bool isDataView() const { return false; } 41 enum ViewType { 42 TypeInt8, 43 TypeUint8, 44 TypeUint8Clamped, 45 TypeInt16, 46 TypeUint16, 47 TypeInt32, 48 TypeUint32, 49 TypeFloat32, 50 TypeFloat64, 51 TypeDataView 52 }; 53 virtual ViewType getType() const = 0; 51 54 52 55 PassRefPtr<ArrayBuffer> buffer() const -
trunk/Source/WTF/wtf/Float32Array.h
r111778 r123819 49 49 } 50 50 51 // Invoked by the indexed getter. Does not perform range checks; caller52 // is responsible for doing so and returning undefined as necessary.53 float item(unsigned index) const54 {55 ASSERT(index < TypedArrayBase<float>::m_length);56 float result = TypedArrayBase<float>::data()[index];57 return result;58 }59 60 51 inline PassRefPtr<Float32Array> subarray(int start) const; 61 52 inline PassRefPtr<Float32Array> subarray(int start, int end) const; 53 54 virtual ViewType getType() const 55 { 56 return TypeFloat32; 57 } 62 58 63 59 private: … … 67 63 // Make constructor visible to superclass. 68 64 friend class TypedArrayBase<float>; 69 70 // Overridden from ArrayBufferView.71 virtual bool isFloatArray() const { return true; }72 65 }; 73 66 -
trunk/Source/WTF/wtf/Float64Array.h
r111778 r123819 49 49 } 50 50 51 // Invoked by the indexed getter. Does not perform range checks; caller52 // is responsible for doing so and returning undefined as necessary.53 double item(unsigned index) const54 {55 ASSERT(index < TypedArrayBase<double>::m_length);56 double result = TypedArrayBase<double>::data()[index];57 return result;58 }59 60 51 inline PassRefPtr<Float64Array> subarray(int start) const; 61 52 inline PassRefPtr<Float64Array> subarray(int start, int end) const; 53 54 virtual ViewType getType() const 55 { 56 return TypeFloat64; 57 } 62 58 63 59 private: … … 67 63 // Make constructor visible to superclass. 68 64 friend class TypedArrayBase<double>; 69 70 // Overridden from ArrayBufferView.71 virtual bool isDoubleArray() const { return true; }72 65 }; 73 66 -
trunk/Source/WTF/wtf/Int16Array.h
r111778 r123819 46 46 inline PassRefPtr<Int16Array> subarray(int start, int end) const; 47 47 48 virtual ViewType getType() const 49 { 50 return TypeInt16; 51 } 52 48 53 private: 49 54 inline Int16Array(PassRefPtr<ArrayBuffer>, … … 52 57 // Make constructor visible to superclass. 53 58 friend class TypedArrayBase<short>; 54 55 // Overridden from ArrayBufferView.56 virtual bool isShortArray() const { return true; }57 59 }; 58 60 -
trunk/Source/WTF/wtf/Int32Array.h
r111778 r123819 45 45 inline PassRefPtr<Int32Array> subarray(int start, int end) const; 46 46 47 virtual ViewType getType() const 48 { 49 return TypeInt32; 50 } 51 47 52 private: 48 53 inline Int32Array(PassRefPtr<ArrayBuffer>, … … 51 56 // Make constructor visible to superclass. 52 57 friend class TypedArrayBase<int>; 53 54 // Overridden from ArrayBufferView.55 virtual bool isIntArray() const { return true; }56 58 }; 57 59 -
trunk/Source/WTF/wtf/Int8Array.h
r111778 r123819 47 47 inline PassRefPtr<Int8Array> subarray(int start, int end) const; 48 48 49 virtual ViewType getType() const 50 { 51 return TypeInt8; 52 } 53 49 54 private: 50 55 inline Int8Array(PassRefPtr<ArrayBuffer>, … … 53 58 // Make constructor visible to superclass. 54 59 friend class TypedArrayBase<signed char>; 55 56 // Overridden from ArrayBufferView.57 virtual bool isByteArray() const { return true; }58 60 }; 59 61 -
trunk/Source/WTF/wtf/IntegralTypedArrayBase.h
r111778 r123819 51 51 } 52 52 53 // Invoked by the indexed getter. Does not perform range checks; caller54 // is responsible for doing so and returning undefined as necessary.55 T item(unsigned index) const56 {57 ASSERT(index < TypedArrayBase<T>::m_length);58 return TypedArrayBase<T>::data()[index];59 }60 61 53 protected: 62 54 IntegralTypedArrayBase(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) -
trunk/Source/WTF/wtf/TypedArrayBase.h
r114992 r123819 64 64 { 65 65 return m_length * sizeof(T); 66 } 67 68 // Invoked by the indexed getter. Does not perform range checks; caller 69 // is responsible for doing so and returning undefined as necessary. 70 T item(unsigned index) const 71 { 72 ASSERT(index < TypedArrayBase<T>::m_length); 73 return TypedArrayBase<T>::data()[index]; 66 74 } 67 75 -
trunk/Source/WTF/wtf/Uint16Array.h
r111778 r123819 47 47 inline PassRefPtr<Uint16Array> subarray(int start, int end) const; 48 48 49 virtual ViewType getType() const 50 { 51 return TypeUint16; 52 } 53 49 54 private: 50 55 inline Uint16Array(PassRefPtr<ArrayBuffer>, … … 53 58 // Make constructor visible to superclass. 54 59 friend class TypedArrayBase<unsigned short>; 55 56 // Overridden from ArrayBufferView.57 virtual bool isUnsignedShortArray() const { return true; }58 60 }; 59 61 -
trunk/Source/WTF/wtf/Uint32Array.h
r111778 r123819 47 47 inline PassRefPtr<Uint32Array> subarray(int start, int end) const; 48 48 49 virtual ViewType getType() const 50 { 51 return TypeUint32; 52 } 53 49 54 private: 50 55 inline Uint32Array(PassRefPtr<ArrayBuffer>, … … 53 58 // Make constructor visible to superclass. 54 59 friend class TypedArrayBase<unsigned int>; 55 56 // Overridden from ArrayBufferView.57 virtual bool isUnsignedIntArray() const { return true; }58 60 }; 59 61 -
trunk/Source/WTF/wtf/Uint8Array.h
r111778 r123819 47 47 inline PassRefPtr<Uint8Array> subarray(int start, int end) const; 48 48 49 virtual ViewType getType() const 50 { 51 return TypeUint8; 52 } 53 49 54 protected: 50 55 inline Uint8Array(PassRefPtr<ArrayBuffer>, … … 53 58 // Make constructor visible to superclass. 54 59 friend class TypedArrayBase<unsigned char>; 55 56 // Overridden from ArrayBufferView.57 virtual bool isUnsignedByteArray() const { return true; }58 60 }; 59 61 -
trunk/Source/WTF/wtf/Uint8ClampedArray.h
r114992 r123819 56 56 inline PassRefPtr<Uint8ClampedArray> subarray(int start, int end) const; 57 57 58 virtual ViewType getType() const 59 { 60 return TypeUint8Clamped; 61 } 62 58 63 private: 59 64 inline Uint8ClampedArray(PassRefPtr<ArrayBuffer>, … … 62 67 // Make constructor visible to superclass. 63 68 friend class TypedArrayBase<unsigned char>; 64 65 // Overridden from ArrayBufferView.66 virtual bool isUnsignedByteClampedArray() const { return true; }67 69 }; 68 70 -
trunk/Source/WebCore/ChangeLog
r123818 r123819 1 2012-07-26 Arnaud Renevier <a.renevier@sisa.samsung.com> 2 3 constructing TypedArray from another TypedArray is slow 4 https://bugs.webkit.org/show_bug.cgi?id=90838 5 6 Reviewed by Kenneth Russell. 7 8 When constructing a typed array from an array like element, try to 9 determine if the argument is a typed array. If so, cast the argument 10 to a typed array, and read each element with .item() method. That 11 avoid reading the value as a JSValue, and speedups construction by 12 approximatively 3x (even 30x if TypedArrays are both the same type). 13 14 In order to achieve that, we use virtual getType method. We can use 15 this information to cast the TypedArray to the actual type, and then 16 read the values from the source. 17 18 Introduce constructArrayBufferViewWithTypedArrayArgument template 19 function which returns a new typed array if first argument is a typed 20 array, or 0 otherwise. 21 22 This patch also replaces previous is<Type>Array() calls with new 23 getType method. 24 25 * bindings/js/JSArrayBufferViewHelper.h: 26 (WebCore::constructArrayBufferViewWithTypedArrayArgument): 27 (WebCore): 28 (WebCore::constructArrayBufferView): 29 * bindings/v8/SerializedScriptValue.cpp: 30 * html/canvas/DataView.h: 31 (DataView): 32 (WebCore::DataView::getType): 33 * html/canvas/WebGLRenderingContext.cpp: 34 (WebCore): 35 (WebCore::WebGLRenderingContext::readPixels): 36 (WebCore::WebGLRenderingContext::validateTexFuncData): 37 * page/Crypto.cpp: 38 1 39 2012-07-26 Max Vujovic <mvujovic@adobe.com> 2 40 -
trunk/Source/WebCore/bindings/js/JSArrayBufferViewHelper.h
r101401 r123819 30 30 #include "ExceptionCode.h" 31 31 #include "JSArrayBuffer.h" 32 #include "JSArrayBufferView.h" 32 33 #include "JSDOMBinding.h" 33 34 #include <interpreter/CallFrame.h> … … 37 38 #include <runtime/JSValue.h> 38 39 #include <wtf/ArrayBufferView.h> 40 #include <wtf/TypedArrayBase.h> 39 41 40 42 namespace WebCore { … … 87 89 // If this returns 0, it will already have thrown a JavaScript exception. 88 90 template<class C, typename T> 91 PassRefPtr<C> constructArrayBufferViewWithTypedArrayArgument(JSC::ExecState* exec) 92 { 93 RefPtr<ArrayBufferView> source = toArrayBufferView(exec->argument(0)); 94 if (!source) 95 return 0; 96 97 ArrayBufferView::ViewType sourceType = source->getType(); 98 if (sourceType == ArrayBufferView::TypeDataView) 99 return 0; 100 101 uint32_t length = asObject(exec->argument(0))->get(exec, JSC::Identifier(exec, "length")).toUInt32(exec); 102 RefPtr<C> array = C::create(length); 103 if (!array) { 104 setDOMException(exec, INDEX_SIZE_ERR); 105 return array; 106 } 107 108 if (array->getType() == sourceType) { 109 memcpy(array->baseAddress(), source->baseAddress(), length * sizeof(T)); 110 return array; 111 } 112 113 switch (sourceType) { 114 case ArrayBufferView::TypeInt8: 115 for (unsigned i = 0; i < length; ++i) 116 array->set(i, (T)(static_cast<TypedArrayBase<signed char> *>(source.get())->item(i))); 117 break; 118 case ArrayBufferView::TypeUint8: 119 case ArrayBufferView::TypeUint8Clamped: 120 for (unsigned i = 0; i < length; ++i) 121 array->set(i, (T)(static_cast<TypedArrayBase<unsigned char> *>(source.get())->item(i))); 122 break; 123 case ArrayBufferView::TypeInt16: 124 for (unsigned i = 0; i < length; ++i) 125 array->set(i, (T)(static_cast<TypedArrayBase<signed short> *>(source.get())->item(i))); 126 break; 127 case ArrayBufferView::TypeUint16: 128 for (unsigned i = 0; i < length; ++i) 129 array->set(i, (T)(static_cast<TypedArrayBase<unsigned short> *>(source.get())->item(i))); 130 break; 131 case ArrayBufferView::TypeInt32: 132 for (unsigned i = 0; i < length; ++i) 133 array->set(i, (T)(static_cast<TypedArrayBase<int> *>(source.get())->item(i))); 134 break; 135 case ArrayBufferView::TypeUint32: 136 for (unsigned i = 0; i < length; ++i) 137 array->set(i, (T)(static_cast<TypedArrayBase<unsigned int> *>(source.get())->item(i))); 138 break; 139 case ArrayBufferView::TypeFloat32: 140 for (unsigned i = 0; i < length; ++i) 141 array->set(i, (T)(static_cast<TypedArrayBase<float> *>(source.get())->item(i))); 142 break; 143 case ArrayBufferView::TypeFloat64: 144 for (unsigned i = 0; i < length; ++i) 145 array->set(i, (T)(static_cast<TypedArrayBase<double> *>(source.get())->item(i))); 146 break; 147 default: 148 return 0; 149 } 150 151 return array; 152 } 153 154 // Template function used by XXXArrayConstructors. 155 // If this returns 0, it will already have thrown a JavaScript exception. 156 template<class C, typename T> 89 157 PassRefPtr<C> constructArrayBufferViewWithArrayBufferArgument(JSC::ExecState* exec) 90 158 { … … 139 207 return view; 140 208 209 view = constructArrayBufferViewWithTypedArrayArgument<C, T>(exec); 210 if (view) 211 return view; 212 141 213 JSC::JSObject* srcArray = asObject(exec->argument(0)); 142 214 uint32_t length = srcArray->get(exec, JSC::Identifier(exec, "length")).toUInt32(exec); -
trunk/Source/WebCore/bindings/v8/SerializedScriptValue.cpp
r123269 r123819 413 413 static_cast<const uint8_t*>(arrayBufferView.baseAddress())); 414 414 #endif 415 if (arrayBufferView.isByteArray()) 415 ArrayBufferView::ViewType type = arrayBufferView.getType(); 416 417 if (type == ArrayBufferView::TypeInt8) 416 418 append(ByteArrayTag); 417 else if ( arrayBufferView.isUnsignedByteClampedArray())419 else if (type == ArrayBufferView::TypeUint8Clamped) 418 420 append(UnsignedByteClampedArrayTag); 419 else if ( arrayBufferView.isUnsignedByteArray())421 else if (type == ArrayBufferView::TypeUint8) 420 422 append(UnsignedByteArrayTag); 421 else if ( arrayBufferView.isShortArray())423 else if (type == ArrayBufferView::TypeInt16) 422 424 append(ShortArrayTag); 423 else if ( arrayBufferView.isUnsignedShortArray())425 else if (type == ArrayBufferView::TypeUint16) 424 426 append(UnsignedShortArrayTag); 425 else if ( arrayBufferView.isIntArray())427 else if (type == ArrayBufferView::TypeInt32) 426 428 append(IntArrayTag); 427 else if ( arrayBufferView.isUnsignedIntArray())429 else if (type == ArrayBufferView::TypeUint32) 428 430 append(UnsignedIntArrayTag); 429 else if ( arrayBufferView.isFloatArray())431 else if (type == ArrayBufferView::TypeFloat32) 430 432 append(FloatArrayTag); 431 else if ( arrayBufferView.isDoubleArray())433 else if (type == ArrayBufferView::TypeFloat64) 432 434 append(DoubleArrayTag); 433 else if ( arrayBufferView.isDataView())435 else if (type == ArrayBufferView::TypeDataView) 434 436 append(DataViewTag); 435 437 else -
trunk/Source/WebCore/html/canvas/DataView.h
r102869 r123819 39 39 static PassRefPtr<DataView> create(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned byteLength); 40 40 41 virtual bool isDataView() const { return true; }42 41 virtual unsigned length() const { return m_byteLength; } 43 42 virtual unsigned byteLength() const { return m_byteLength; } … … 74 73 void setFloat64(unsigned byteOffset, double value, bool littleEndian, ExceptionCode&); 75 74 75 virtual ViewType getType() const 76 { 77 return TypeDataView; 78 } 79 76 80 protected: 77 81 virtual void neuter(); -
trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp
r123816 r123819 3281 3281 } 3282 3282 // Validate array type against pixel type. 3283 if ( !pixels->isUnsignedByteArray()) {3283 if (pixels->getType() != ArrayBufferView::TypeUint8) { 3284 3284 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "ArrayBufferView not Uint8Array"); 3285 3285 return; … … 4938 4938 switch (type) { 4939 4939 case GraphicsContext3D::UNSIGNED_BYTE: 4940 if ( !pixels->isUnsignedByteArray()) {4940 if (pixels->getType() != ArrayBufferView::TypeUint8) { 4941 4941 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "type UNSIGNED_BYTE but ArrayBufferView not Uint8Array"); 4942 4942 return false; … … 4946 4946 case GraphicsContext3D::UNSIGNED_SHORT_4_4_4_4: 4947 4947 case GraphicsContext3D::UNSIGNED_SHORT_5_5_5_1: 4948 if ( !pixels->isUnsignedShortArray()) {4948 if (pixels->getType() != ArrayBufferView::TypeUint16) { 4949 4949 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "type UNSIGNED_SHORT but ArrayBufferView not Uint16Array"); 4950 4950 return false; … … 4952 4952 break; 4953 4953 case GraphicsContext3D::FLOAT: // OES_texture_float 4954 if ( !pixels->isFloatArray()) {4954 if (pixels->getType() != ArrayBufferView::TypeFloat32) { 4955 4955 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "type FLOAT but ArrayBufferView not Float32Array"); 4956 4956 return false; -
trunk/Source/WebCore/page/Crypto.cpp
r105705 r123819 32 32 33 33 #include "ExceptionCode.h" 34 #include <wtf/ Uint8Array.h>34 #include <wtf/ArrayBufferView.h> 35 35 #include <wtf/CryptographicallyRandomNumber.h> 36 36 … … 41 41 bool isIntegerArray(ArrayBufferView* array) 42 42 { 43 return array->isByteArray() 44 || array->isUnsignedByteArray() 45 || array->isUnsignedByteClampedArray() 46 || array->isShortArray() 47 || array->isUnsignedShortArray() 48 || array->isIntArray() 49 || array->isUnsignedIntArray(); 43 ArrayBufferView::ViewType type = array->getType(); 44 return type == ArrayBufferView::TypeInt8 45 || type == ArrayBufferView::TypeUint8 46 || type == ArrayBufferView::TypeUint8Clamped 47 || type == ArrayBufferView::TypeInt16 48 || type == ArrayBufferView::TypeUint16 49 || type == ArrayBufferView::TypeInt32 50 || type == ArrayBufferView::TypeUint32; 50 51 } 51 52
Note: See TracChangeset
for help on using the changeset viewer.