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

Side by Side Diff: vm/object.cc

Issue 11443024: Restructure Add and SetAt to not create a Handle. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « vm/object.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 11153 matching lines...) Expand 10 before | Expand all | Expand 10 after
11164 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space)); 11164 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space));
11165 } 11165 }
11166 11166
11167 11167
11168 const char* ImmutableArray::ToCString() const { 11168 const char* ImmutableArray::ToCString() const {
11169 return "ImmutableArray"; 11169 return "ImmutableArray";
11170 } 11170 }
11171 11171
11172 11172
11173 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { 11173 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const {
11174 Add(Isolate::Current(), value, space);
11175 }
11176
11177
11178 void GrowableObjectArray::Add(Isolate* isolate,
11179 const Object& value,
11180 Heap::Space space) const {
11181 ASSERT(!IsNull()); 11174 ASSERT(!IsNull());
11182 Array& contents = Array::Handle(isolate, data());
11183 if (Length() == Capacity()) { 11175 if (Length() == Capacity()) {
11184 // TODO(Issue 2500): Need a better growth strategy. 11176 // TODO(Issue 2500): Need a better growth strategy.
11185 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2; 11177 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2;
11186 if (new_capacity <= Capacity()) { 11178 if (new_capacity <= Capacity()) {
11187 // Use the preallocated out of memory exception to avoid calling 11179 // Use the preallocated out of memory exception to avoid calling
11188 // into dart code or allocating any code. 11180 // into dart code or allocating any code.
11181 Isolate* isolate = Isolate::Current();
11189 const Instance& exception = 11182 const Instance& exception =
11190 Instance::Handle(isolate->object_store()->out_of_memory()); 11183 Instance::Handle(isolate->object_store()->out_of_memory());
11191 Exceptions::Throw(exception); 11184 Exceptions::Throw(exception);
11192 UNREACHABLE(); 11185 UNREACHABLE();
11193 } 11186 }
11194 Grow(new_capacity, space); 11187 Grow(new_capacity, space);
11195 contents = data();
11196 } 11188 }
11197 ASSERT(Length() < Capacity()); 11189 ASSERT(Length() < Capacity());
11198 intptr_t index = Length(); 11190 intptr_t index = Length();
11199 SetLength(index + 1); 11191 SetLength(index + 1);
11200 contents.SetAt(index, value); 11192 SetAt(index, value);
11201 } 11193 }
11202 11194
11203 11195
11204 void GrowableObjectArray::Grow(intptr_t new_capacity, Heap::Space space) const { 11196 void GrowableObjectArray::Grow(intptr_t new_capacity, Heap::Space space) const {
11205 ASSERT(new_capacity > Capacity()); 11197 ASSERT(new_capacity > Capacity());
11206 const Array& contents = Array::Handle(data()); 11198 const Array& contents = Array::Handle(data());
11207 const Array& new_contents = 11199 const Array& new_contents =
11208 Array::Handle(Array::Grow(contents, new_capacity, space)); 11200 Array::Handle(Array::Grow(contents, new_capacity, space));
11209 StorePointer(&(raw_ptr()->data_), new_contents.raw()); 11201 StorePointer(&(raw_ptr()->data_), new_contents.raw());
11210 ASSERT(AbstractTypeArguments::AreEqual( 11202 ASSERT(AbstractTypeArguments::AreEqual(
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
12119 } 12111 }
12120 return result.raw(); 12112 return result.raw();
12121 } 12113 }
12122 12114
12123 12115
12124 const char* WeakProperty::ToCString() const { 12116 const char* WeakProperty::ToCString() const {
12125 return "_WeakProperty"; 12117 return "_WeakProperty";
12126 } 12118 }
12127 12119
12128 } // namespace dart 12120 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698