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

Unified Diff: runtime/lib/array.cc

Issue 533483003: Cleanup throwing of the RangeError in the runtime to remove duplicated code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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/growable_array.cc » ('j') | runtime/vm/exceptions.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/array.cc
diff --git a/runtime/lib/array.cc b/runtime/lib/array.cc
index 7d9e076583483ae407786cab564af3ded01a1173..ec8d120cd926f3f6b18dc59713addbb2e5917b38 100644
--- a/runtime/lib/array.cc
+++ b/runtime/lib/array.cc
@@ -23,9 +23,7 @@ DEFINE_NATIVE_ENTRY(List_getIndexed, 2) {
const Array& array = Array::CheckedHandle(arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
if ((index.Value() < 0) || (index.Value() >= array.Length())) {
- const Array& args = Array::Handle(Array::New(1));
- args.SetAt(0, index);
- Exceptions::ThrowByType(Exceptions::kRange, args);
+ Exceptions::ThrowRangeError(index);
}
return array.At(index.Value());
}
@@ -36,9 +34,7 @@ DEFINE_NATIVE_ENTRY(List_setIndexed, 3) {
GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1));
const Instance& value = Instance::CheckedHandle(arguments->NativeArgAt(2));
if ((index.Value() < 0) || (index.Value() >= array.Length())) {
- const Array& args = Array::Handle(Array::New(1));
- args.SetAt(0, index);
- Exceptions::ThrowByType(Exceptions::kRange, args);
+ Exceptions::ThrowRangeError(index);
}
array.SetAt(index.Value(), value);
return Object::null();
@@ -58,38 +54,7 @@ DEFINE_NATIVE_ENTRY(List_copyFromObjectArray, 5) {
GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(2));
GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(3));
GET_NON_NULL_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(4));
- intptr_t icount = count.Value();
- if (icount < 0) {
- Exceptions::ThrowByType(Exceptions::kArgument, Object::empty_array());
- }
- if (icount == 0) {
- return Object::null();
- }
- intptr_t isrc_start = src_start.Value();
- intptr_t idst_start = dst_start.Value();
- if ((isrc_start < 0) || ((isrc_start + icount) > source.Length())) {
- const Array& args = Array::Handle(Array::New(1));
- args.SetAt(0, src_start);
- Exceptions::ThrowByType(Exceptions::kRange, args);
- }
- if ((idst_start < 0) || ((idst_start + icount) > dest.Length())) {
- const Array& args = Array::Handle(Array::New(1));
- args.SetAt(0, dst_start);
- Exceptions::ThrowByType(Exceptions::kRange, args);
- }
-
- Object& src_obj = Object::Handle();
Ivan Posva 2014/09/02 15:27:07 PassiveObject& src_obj = ... Since we do not need
Vyacheslav Egorov (Google) 2014/09/02 16:02:53 PassiveObject& brings around 1.5x-2x improvement.
- if (isrc_start < idst_start) {
- for (intptr_t i = icount - 1; i >= 0; i--) {
- src_obj = source.At(isrc_start + i);
- dest.SetAt(idst_start + i, src_obj);
- }
- } else {
- for (intptr_t i = 0; i < icount; i++) {
- src_obj = source.At(isrc_start + i);
- dest.SetAt(idst_start + i, src_obj);
- }
- }
+ dest.CopyFrom(dst_start.Value(), source, src_start.Value(), count.Value());
return Object::null();
}
« no previous file with comments | « no previous file | runtime/lib/growable_array.cc » ('j') | runtime/vm/exceptions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698