- Revision
- 95157
- Author
- commit-qu...@webkit.org
- Date
- 2011-09-14 20:28:43 -0700 (Wed, 14 Sep 2011)
Log Message
[v8] Improve performance of typed array copy constructor taking Array
https://bugs.webkit.org/show_bug.cgi?id=68015
Patch by Ulan Degenbaev <u...@chromium.org> on 2011-09-14
Reviewed by Kenneth Russell.
Invoke the 'set' method of the constructed array instead of
copying the elements of the source array one by one.
Copy constructor tests already exist.
* ../../Source/WebCore/WebCore.gypi:
* ../../Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.cpp: Added.
* ../../Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h:
Modified Paths
Added Paths
Diff
Modified: trunk/ChangeLog (95156 => 95157)
--- trunk/ChangeLog 2011-09-15 03:04:37 UTC (rev 95156)
+++ trunk/ChangeLog 2011-09-15 03:28:43 UTC (rev 95157)
@@ -1,3 +1,19 @@
+2011-09-14 Ulan Degenbaev <u...@chromium.org>
+
+ [v8] Improve performance of typed array copy constructor taking Array
+ https://bugs.webkit.org/show_bug.cgi?id=68015
+
+ Reviewed by Kenneth Russell.
+
+ Invoke the 'set' method of the constructed array instead of
+ copying the elements of the source array one by one.
+
+ Copy constructor tests already exist.
+
+ * ../../Source/WebCore/WebCore.gypi:
+ * ../../Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.cpp: Added.
+ * ../../Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h:
+
2011-09-14 Csaba Osztrogonác <o...@webkit.org>
[GTK] Unreviewed buildfix after r95107.
Modified: trunk/Source/WebCore/WebCore.gypi (95156 => 95157)
--- trunk/Source/WebCore/WebCore.gypi 2011-09-15 03:04:37 UTC (rev 95156)
+++ trunk/Source/WebCore/WebCore.gypi 2011-09-15 03:28:43 UTC (rev 95157)
@@ -2116,6 +2116,7 @@
'bindings/v8/WorldContextHandle.h',
'bindings/v8/WrapperTypeInfo.h',
'bindings/v8/custom/V8ArrayBufferCustom.cpp',
+ 'bindings/v8/custom/V8ArrayBufferViewCustom.cpp',
'bindings/v8/custom/V8ArrayBufferViewCustom.h',
'bindings/v8/custom/V8AudioBufferSourceNodeCustom.cpp',
'bindings/v8/custom/V8AudioContextCustom.cpp',
Added: trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.cpp (0 => 95157)
--- trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.cpp (rev 0)
+++ trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.cpp 2011-09-15 03:28:43 UTC (rev 95157)
@@ -0,0 +1,41 @@
+
+/*
+ * Copyright (C) 2011 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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.
+ */
+
+#include "config.h"
+#include "V8ArrayBufferViewCustom.h"
+
+#include <v8.h>
+
+namespace WebCore {
+
+void copyElements(v8::Handle<v8::Object> destArray, v8::Handle<v8::Object> srcArray)
+{
+ v8::Handle<v8::String> key = v8::String::New("set");
+ v8::Handle<v8::Function> set = destArray->Get(key).As<v8::Function>();
+ v8::Handle<v8::Value> argument = srcArray;
+ set->Call(destArray, 1, &argument);
+}
+
+}
Modified: trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h (95156 => 95157)
--- trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h 2011-09-15 03:04:37 UTC (rev 95156)
+++ trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h 2011-09-15 03:28:43 UTC (rev 95157)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 Google Inc. All rights reserved.
+ * Copyright (C) 2009, 2011 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
@@ -32,6 +32,7 @@
#define V8ArrayBufferViewCustom_h
#include "ArrayBuffer.h"
+#include "ExceptionCode.h"
#include "V8ArrayBuffer.h"
#include "V8Binding.h"
@@ -39,6 +40,11 @@
namespace WebCore {
+
+// Copy the elements from the source array to the typed destination array by
+// invoking the 'set' method of the destination array in JS.
+void copyElements(v8::Handle<v8::Object> destArray, v8::Handle<v8::Object> srcArray);
+
// Template function used by the ArrayBufferView*Constructor callbacks.
template<class ArrayClass, class ElementType>
v8::Handle<v8::Value> constructWebGLArrayWithArrayBufferArgument(const v8::Arguments& args, WrapperTypeInfo* type, v8::ExternalArrayType arrayType, bool hasIndexer)
@@ -147,17 +153,14 @@
if (!array.get())
return throwError("ArrayBufferView size is not a small enough positive integer.", V8Proxy::RangeError);
- if (!srcArray.IsEmpty()) {
- // Need to copy the incoming array into the newly created ArrayBufferView.
- for (unsigned i = 0; i < len; i++) {
- v8::Local<v8::Value> val = srcArray->Get(i);
- array->set(i, val->NumberValue());
- }
- }
// Transform the holder into a wrapper object for the array.
V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get());
args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddress(), arrayType, array.get()->length());
+
+ if (!srcArray.IsEmpty())
+ copyElements(args.Holder(), srcArray);
+
return toV8(array.release(), args.Holder(), MarkIndependent);
}