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

Unified Diff: runtime/vm/object.cc

Issue 536043002: Merge array allocation and List._copyFromObjectArray to provide fast path for large arrays. (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 | « runtime/vm/object.h ('k') | tests/language/list_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 2d0fca9b2ed981a2c68ce1f317795d1ca31a7be8..c5c421cf4f9d80f4b8de89b5efe40fcee06301a9 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -18097,6 +18097,32 @@ RawArray* Array::New(intptr_t class_id, intptr_t len, Heap::Space space) {
}
+RawArray* Array::Slice(intptr_t start,
+ intptr_t count,
+ bool with_type_argument) const {
+ // TODO(vegorov) introduce an array allocation method that fills newly
+ // allocated array with values from the given source array instead of
+ // null-initializing all elements.
+ Array& dest = Array::Handle(Array::New(count));
+ if (dest.raw()->IsNewObject()) {
+ NoGCScope no_gc_scope;
+ memmove(dest.ObjectAddr(0), ObjectAddr(start), count * kWordSize);
+ } else {
+ PassiveObject& obj = PassiveObject::Handle();
+ for (intptr_t i = 0; i < count; i++) {
+ obj = At(start + i);
+ dest.SetAt(i, obj);
+ }
+ }
+
+ if (with_type_argument) {
+ dest.SetTypeArguments(TypeArguments::Handle(GetTypeArguments()));
+ }
+
+ return dest.raw();
+}
+
+
void Array::MakeImmutable() const {
NoGCScope no_gc;
uword tags = raw_ptr()->tags_;
« no previous file with comments | « runtime/vm/object.h ('k') | tests/language/list_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698