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

Unified Diff: runtime/lib/typeddata.cc

Issue 12608006: Use offsetInBytes and not index in the get/set accessors of views. (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') | runtime/lib/typeddata.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/typeddata.cc
===================================================================
--- runtime/lib/typeddata.cc (revision 19984)
+++ runtime/lib/typeddata.cc (working copy)
@@ -109,18 +109,16 @@
#define TYPED_DATA_GETTER(getter, object) \
DEFINE_NATIVE_ENTRY(TypedData_##getter, 2) { \
GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \
- GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); \
+ GET_NON_NULL_NATIVE_ARGUMENT(Smi, offsetInBytes, arguments->NativeArgAt(1)); \
if (instance.IsTypedData()) { \
const TypedData& array = TypedData::Cast(instance); \
- intptr_t offsetInBytes = index.Value() * array.ElementSizeInBytes(); \
- ASSERT(RangeCheck(offsetInBytes, array.LengthInBytes())); \
- return object::New(array.getter(offsetInBytes)); \
+ ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \
+ return object::New(array.getter(offsetInBytes.Value())); \
} \
if (instance.IsExternalTypedData()) { \
const ExternalTypedData& array = ExternalTypedData::Cast(instance); \
- intptr_t offsetInBytes = index.Value() * array.ElementSizeInBytes(); \
- ASSERT(RangeCheck(offsetInBytes, array.LengthInBytes())); \
- return object::New(array.getter(offsetInBytes)); \
+ ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \
+ return object::New(array.getter(offsetInBytes.Value())); \
} \
const String& error = String::Handle(String::NewFormatted( \
"Expected a TypedData object but found %s", instance.ToCString())); \
@@ -134,18 +132,16 @@
#define TYPED_DATA_SETTER(setter, object, get_object_value) \
DEFINE_NATIVE_ENTRY(TypedData_##setter, 3) { \
GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \
- GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); \
+ GET_NON_NULL_NATIVE_ARGUMENT(Smi, offsetInBytes, arguments->NativeArgAt(1)); \
GET_NON_NULL_NATIVE_ARGUMENT(object, value, arguments->NativeArgAt(2)); \
if (instance.IsTypedData()) { \
const TypedData& array = TypedData::Cast(instance); \
- intptr_t offsetInBytes = index.Value() * array.ElementSizeInBytes(); \
- ASSERT(RangeCheck(offsetInBytes, array.LengthInBytes())); \
- array.setter(offsetInBytes, value.get_object_value()); \
+ ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \
+ array.setter(offsetInBytes.Value(), value.get_object_value()); \
} else if (instance.IsExternalTypedData()) { \
const ExternalTypedData& array = ExternalTypedData::Cast(instance); \
- intptr_t offsetInBytes = index.Value() * array.ElementSizeInBytes(); \
- ASSERT(RangeCheck(offsetInBytes, array.LengthInBytes())); \
- array.setter(offsetInBytes, value.get_object_value()); \
+ ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \
+ array.setter(offsetInBytes.Value(), value.get_object_value()); \
} else { \
const String& error = String::Handle(String::NewFormatted( \
"Expected a TypedData object but found %s", instance.ToCString())); \
@@ -160,18 +156,16 @@
#define TYPED_DATA_UINT64_GETTER(getter, object) \
DEFINE_NATIVE_ENTRY(TypedData_##getter, 2) { \
GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \
- GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); \
+ GET_NON_NULL_NATIVE_ARGUMENT(Smi, offsetInBytes, arguments->NativeArgAt(1)); \
uint64_t value = 0; \
if (instance.IsTypedData()) { \
const TypedData& array = TypedData::Cast(instance); \
- intptr_t offsetInBytes = index.Value() * array.ElementSizeInBytes(); \
- ASSERT(RangeCheck(offsetInBytes, array.LengthInBytes())); \
- value = array.getter(offsetInBytes); \
+ ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \
+ value = array.getter(offsetInBytes.Value()); \
} else if (instance.IsExternalTypedData()) { \
const ExternalTypedData& array = ExternalTypedData::Cast(instance); \
- intptr_t offsetInBytes = index.Value() * array.ElementSizeInBytes(); \
- ASSERT(RangeCheck(offsetInBytes, array.LengthInBytes())); \
- value = array.getter(offsetInBytes); \
+ ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \
+ value = array.getter(offsetInBytes.Value()); \
} else { \
const String& error = String::Handle(String::NewFormatted( \
"Expected a TypedData object but found %s", instance.ToCString())); \
@@ -196,7 +190,7 @@
#define TYPED_DATA_UINT64_SETTER(setter, object) \
DEFINE_NATIVE_ENTRY(TypedData_##setter, 3) { \
GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \
- GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); \
+ GET_NON_NULL_NATIVE_ARGUMENT(Smi, offsetInBytes, arguments->NativeArgAt(1)); \
Anders Johnsen 2013/03/14 09:06:57 Random question: What if it's not a Smi? Do we wan
Florian Schneider 2013/03/14 09:47:22 Currently we don't. Arrays have a maximum length o
siva 2013/03/14 11:16:34 Yes, as Florian points out we have a length check
GET_NON_NULL_NATIVE_ARGUMENT(object, value, arguments->NativeArgAt(2)); \
uint64_t object_value; \
if (value.IsBigint()) { \
@@ -209,14 +203,12 @@
} \
if (instance.IsTypedData()) { \
const TypedData& array = TypedData::Cast(instance); \
- intptr_t offsetInBytes = index.Value() * array.ElementSizeInBytes(); \
- ASSERT(RangeCheck(offsetInBytes, array.LengthInBytes())); \
- array.setter(offsetInBytes, object_value); \
+ ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \
+ array.setter(offsetInBytes.Value(), object_value); \
} else if (instance.IsExternalTypedData()) { \
const ExternalTypedData& array = ExternalTypedData::Cast(instance); \
- intptr_t offsetInBytes = index.Value() * array.ElementSizeInBytes(); \
- ASSERT(RangeCheck(offsetInBytes, array.LengthInBytes())); \
- array.setter(offsetInBytes, object_value); \
+ ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \
+ array.setter(offsetInBytes.Value(), object_value); \
} else { \
const String& error = String::Handle(String::NewFormatted( \
"Expected a TypedData object but found %s", instance.ToCString())); \
« no previous file with comments | « no previous file | runtime/lib/typeddata.dart » ('j') | runtime/lib/typeddata.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698