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

Unified Diff: runtime/lib/typeddata.cc

Issue 12881006: Add the native intrinsic TypedData_setRange to optimize the setRange call when the destination and … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 | runtime/lib/typeddata.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/typeddata.cc
===================================================================
--- runtime/lib/typeddata.cc (revision 20057)
+++ runtime/lib/typeddata.cc (working copy)
@@ -15,14 +15,31 @@
// TypedData.
-// Checks to see if offsetInBytes is in the range.
-static bool RangeCheck(intptr_t offsetInBytes, intptr_t lengthInBytes) {
- return ((offsetInBytes >= 0) &&
- (lengthInBytes > 0) &&
- (offsetInBytes < lengthInBytes));
+// Checks to see if offset_in_bytes is in the range.
+static bool RangeCheck(intptr_t offset_in_bytes, intptr_t length_in_bytes) {
+ return ((offset_in_bytes >= 0) &&
+ (length_in_bytes > 0) &&
+ (offset_in_bytes < length_in_bytes));
}
+// Checks to see if offsetInBytes + num_bytes is in the range.
+static void SetRangeCheck(intptr_t offset_in_bytes,
+ intptr_t num_bytes,
+ intptr_t length_in_bytes,
+ intptr_t element_size_in_bytes) {
+ if (!Utils::RangeCheck(offset_in_bytes, num_bytes, length_in_bytes)) {
+ const String& error = String::Handle(String::NewFormatted(
+ "index (%"Pd") must be in the range [0..%"Pd")",
+ (offset_in_bytes / element_size_in_bytes),
+ (length_in_bytes / element_size_in_bytes)));
+ const Array& args = Array::Handle(Array::New(1));
+ args.SetAt(0, error);
+ Exceptions::ThrowByType(Exceptions::kRange, args);
+ }
+}
+
+
// Checks to see if a length will not result in an OOM error.
static void LengthCheck(intptr_t len, intptr_t max) {
ASSERT(len >= 0);
@@ -62,6 +79,55 @@
}
+#define COPY_DATA(type, dst, src) \
+ const type& dst_array = type::Cast(dst); \
+ const type& src_array = type::Cast(src); \
+ intptr_t element_size_in_bytes = dst_array.ElementSizeInBytes(); \
+ intptr_t length_in_bytes = length.Value() * element_size_in_bytes; \
+ intptr_t src_offset_in_bytes = src_start.Value() * element_size_in_bytes; \
+ intptr_t dst_offset_in_bytes = dst_start.Value() * element_size_in_bytes; \
+ SetRangeCheck(src_offset_in_bytes, \
+ length_in_bytes, \
+ src_array.LengthInBytes(), \
+ element_size_in_bytes); \
+ SetRangeCheck(dst_offset_in_bytes, \
+ length_in_bytes, \
+ dst_array.LengthInBytes(), \
+ element_size_in_bytes); \
+ type::Copy(dst_array, dst_offset_in_bytes, \
+ src_array, src_offset_in_bytes, \
+ length_in_bytes);
+
+DEFINE_NATIVE_ENTRY(TypedData_setRange, 5) {
+ GET_NON_NULL_NATIVE_ARGUMENT(Instance, dst, arguments->NativeArgAt(0));
+ GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1));
+ GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2));
+ GET_NON_NULL_NATIVE_ARGUMENT(Instance, src, arguments->NativeArgAt(3));
+ GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4));
+
+ if (length.Value() < 0) {
+ const String& error = String::Handle(String::NewFormatted(
+ "length (%"Pd") must be non-negative", length.Value()));
+ const Array& args = Array::Handle(Array::New(1));
+ args.SetAt(0, error);
+ Exceptions::ThrowByType(Exceptions::kArgument, args);
+ }
+ if ((dst.IsTypedData() || dst.IsExternalTypedData()) &&
+ (dst.clazz() == src.clazz())) {
+ if (dst.IsTypedData()) {
+ ASSERT(src.IsTypedData());
+ COPY_DATA(TypedData, dst, src);
+ } else {
+ ASSERT(src.IsExternalTypedData());
+ ASSERT(dst.IsExternalTypedData());
+ COPY_DATA(ExternalTypedData, dst, src);
+ }
+ return Bool::True().raw();
+ }
+ return Bool::False().raw();
+}
+
+
// We check the length parameter against a possible maximum length for the
// array based on available physical addressable memory on the system. The
// maximum possible length is a scaled value of kSmiMax which is set up based
« no previous file with comments | « no previous file | runtime/lib/typeddata.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698