Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1094)

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 300003006: Add fast path to ListGetAsBytes for byte-size ExternalTypedData. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: fixed assertion Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 36670)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -2686,12 +2686,11 @@
} \
return Api::NewError("Invalid length passed in to access array elements"); \
-
-static Dart_Handle CopyBytes(const TypedData& array,
+template<typename T>
+static Dart_Handle CopyBytes(const T& array,
intptr_t offset,
uint8_t* native_array,
intptr_t length) {
- ASSERT(array.IsTypedData());
ASSERT(array.ElementSizeInBytes() == 1);
NoGCScope no_gc;
memmove(native_array,
@@ -2718,6 +2717,16 @@
return CopyBytes(array, offset, native_array, length);
}
}
+ if (obj.IsExternalTypedData()) {
+ const ExternalTypedData& external_array = ExternalTypedData::Cast(obj);
+ if (external_array.ElementSizeInBytes() == 1) {
+ if (!Utils::RangeCheck(offset, length, external_array.Length())) {
+ return Api::NewError(
+ "Invalid length passed in to access list elements");
+ }
+ return CopyBytes(external_array, offset, native_array, length);
+ }
+ }
if (RawObject::IsTypedDataViewClassId(obj.GetClassId())) {
const Instance& view = Instance::Cast(obj);
if (TypedDataView::ElementSizeInBytes(view) == 1) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698