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

Side by Side Diff: runtime/vm/object.cc

Issue 23072013: - Avoid double iteration when accessing anonymous classes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/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/cpu.h" 10 #include "vm/cpu.h"
(...skipping 6298 matching lines...) Expand 10 before | Expand all | Expand 10 after
6309 6309
6310 6310
6311 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const { 6311 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const {
6312 stream->OpenObject(); 6312 stream->OpenObject();
6313 stream->CloseObject(); 6313 stream->CloseObject();
6314 } 6314 }
6315 6315
6316 6316
6317 DictionaryIterator::DictionaryIterator(const Library& library) 6317 DictionaryIterator::DictionaryIterator(const Library& library)
6318 : array_(Array::Handle(library.dictionary())), 6318 : array_(Array::Handle(library.dictionary())),
6319 // Last element in array is a Smi. 6319 // Last element in array is a Smi indicating the number of entries used.
6320 size_(Array::Handle(library.dictionary()).Length() - 1), 6320 size_(Array::Handle(library.dictionary()).Length() - 1),
6321 next_ix_(0) { 6321 next_ix_(0) {
6322 MoveToNextObject(); 6322 MoveToNextObject();
6323 } 6323 }
6324 6324
6325 6325
6326 RawObject* DictionaryIterator::GetNext() { 6326 RawObject* DictionaryIterator::GetNext() {
6327 ASSERT(HasNext()); 6327 ASSERT(HasNext());
6328 int ix = next_ix_++; 6328 int ix = next_ix_++;
6329 MoveToNextObject(); 6329 MoveToNextObject();
6330 ASSERT(array_.At(ix) != Object::null()); 6330 ASSERT(array_.At(ix) != Object::null());
6331 return array_.At(ix); 6331 return array_.At(ix);
6332 } 6332 }
6333 6333
6334 6334
6335 void DictionaryIterator::MoveToNextObject() { 6335 void DictionaryIterator::MoveToNextObject() {
6336 Object& obj = Object::Handle(array_.At(next_ix_)); 6336 Object& obj = Object::Handle(array_.At(next_ix_));
6337 while (obj.IsNull() && HasNext()) { 6337 while (obj.IsNull() && HasNext()) {
6338 next_ix_++; 6338 next_ix_++;
6339 obj = array_.At(next_ix_); 6339 obj = array_.At(next_ix_);
6340 } 6340 }
6341 } 6341 }
6342 6342
6343 6343
6344 ClassDictionaryIterator::ClassDictionaryIterator(const Library& library) 6344 ClassDictionaryIterator::ClassDictionaryIterator(const Library& library,
6345 : DictionaryIterator(library) { 6345 IterationKind kind)
6346 : DictionaryIterator(library),
6347 anon_array_((kind == kIteratePrivate) ?
6348 Array::Handle(library.anonymous_classes()) : Object::empty_array()),
6349 anon_size_((kind == kIteratePrivate) ?
6350 library.num_anonymous_classes() : 0),
6351 anon_ix_(0) {
6346 MoveToNextClass(); 6352 MoveToNextClass();
6347 } 6353 }
6348 6354
6349 6355
6350 RawClass* ClassDictionaryIterator::GetNextClass() { 6356 RawClass* ClassDictionaryIterator::GetNextClass() {
6351 ASSERT(HasNext()); 6357 ASSERT(HasNext());
6352 int ix = next_ix_++; 6358 Class& cls = Class::Handle();
6353 Object& obj = Object::Handle(array_.At(ix)); 6359 if (next_ix_ < size_) {
6354 MoveToNextClass(); 6360 int ix = next_ix_++;
6355 return Class::Cast(obj).raw(); 6361 cls ^= array_.At(ix);
6362 MoveToNextClass();
6363 return cls.raw();
6364 }
6365 ASSERT(anon_ix_ < anon_size_);
6366 cls ^= anon_array_.At(anon_ix_++);
6367 return cls.raw();
6356 } 6368 }
6357 6369
6358 6370
6359 void ClassDictionaryIterator::MoveToNextClass() { 6371 void ClassDictionaryIterator::MoveToNextClass() {
6360 Object& obj = Object::Handle(array_.At(next_ix_)); 6372 Object& obj = Object::Handle();
6361 while (!obj.IsClass() && HasNext()) { 6373 while (next_ix_ < size_) {
6374 obj = array_.At(next_ix_);
6375 if (obj.IsClass()) {
6376 return;
6377 }
6362 next_ix_++; 6378 next_ix_++;
6363 obj = array_.At(next_ix_);
6364 } 6379 }
6365 } 6380 }
6366 6381
6367 6382
6368 LibraryPrefixIterator::LibraryPrefixIterator(const Library& library) 6383 LibraryPrefixIterator::LibraryPrefixIterator(const Library& library)
6369 : DictionaryIterator(library) { 6384 : DictionaryIterator(library) {
6370 Advance(); 6385 Advance();
6371 } 6386 }
6372 6387
6373 6388
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
6740 } 6755 }
6741 } 6756 }
6742 return Script::null(); 6757 return Script::null();
6743 } 6758 }
6744 6759
6745 6760
6746 RawFunction* Library::LookupFunctionInScript(const Script& script, 6761 RawFunction* Library::LookupFunctionInScript(const Script& script,
6747 intptr_t token_pos) const { 6762 intptr_t token_pos) const {
6748 Class& cls = Class::Handle(); 6763 Class& cls = Class::Handle();
6749 Function& func = Function::Handle(); 6764 Function& func = Function::Handle();
6750 ClassDictionaryIterator it(*this); 6765 ClassDictionaryIterator it(*this, ClassDictionaryIterator::kIteratePrivate);
6751 while (it.HasNext()) { 6766 while (it.HasNext()) {
6752 cls = it.GetNextClass(); 6767 cls = it.GetNextClass();
6753 if (script.raw() == cls.script()) { 6768 if (script.raw() == cls.script()) {
6754 func = cls.LookupFunctionAtToken(token_pos); 6769 func = cls.LookupFunctionAtToken(token_pos);
6755 if (!func.IsNull()) { 6770 if (!func.IsNull()) {
6756 return func.raw(); 6771 return func.raw();
6757 } 6772 }
6758 } 6773 }
6759 } 6774 }
6760 // Look in anonymous classes for toplevel functions.
6761 Array& anon_classes = Array::Handle(this->raw_ptr()->anonymous_classes_);
6762 intptr_t num_anonymous = raw_ptr()->num_anonymous_;
6763 for (int i = 0; i < num_anonymous; i++) {
6764 cls ^= anon_classes.At(i);
6765 ASSERT(!cls.IsNull());
6766 if (script.raw() == cls.script()) {
6767 func = cls.LookupFunctionAtToken(token_pos);
6768 if (!func.IsNull()) {
6769 return func.raw();
6770 }
6771 }
6772 }
6773 return Function::null(); 6775 return Function::null();
6774 } 6776 }
6775 6777
6776 6778
6777 RawObject* Library::LookupLocalObject(const String& name) const { 6779 RawObject* Library::LookupLocalObject(const String& name) const {
6778 intptr_t index; 6780 intptr_t index;
6779 return LookupEntry(name, &index); 6781 return LookupEntry(name, &index);
6780 } 6782 }
6781 6783
6782 6784
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
7620 7622
7621 7623
7622 RawError* Library::CompileAll() { 7624 RawError* Library::CompileAll() {
7623 Error& error = Error::Handle(); 7625 Error& error = Error::Handle();
7624 const GrowableObjectArray& libs = GrowableObjectArray::Handle( 7626 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
7625 Isolate::Current()->object_store()->libraries()); 7627 Isolate::Current()->object_store()->libraries());
7626 Library& lib = Library::Handle(); 7628 Library& lib = Library::Handle();
7627 Class& cls = Class::Handle(); 7629 Class& cls = Class::Handle();
7628 for (int i = 0; i < libs.Length(); i++) { 7630 for (int i = 0; i < libs.Length(); i++) {
7629 lib ^= libs.At(i); 7631 lib ^= libs.At(i);
7630 ClassDictionaryIterator it(lib); 7632 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
7631 while (it.HasNext()) { 7633 while (it.HasNext()) {
7632 cls = it.GetNextClass(); 7634 cls = it.GetNextClass();
7633 error = cls.EnsureIsFinalized(Isolate::Current()); 7635 error = cls.EnsureIsFinalized(Isolate::Current());
7634 if (!error.IsNull()) { 7636 if (!error.IsNull()) {
7635 return error.raw(); 7637 return error.raw();
7636 } 7638 }
7637 error = Compiler::CompileAllFunctions(cls); 7639 error = Compiler::CompileAllFunctions(cls);
7638 if (!error.IsNull()) { 7640 if (!error.IsNull()) {
7639 return error.raw(); 7641 return error.raw();
7640 } 7642 }
7641 } 7643 }
7642 Array& anon_classes = Array::Handle(lib.raw_ptr()->anonymous_classes_);
7643 for (int i = 0; i < lib.raw_ptr()->num_anonymous_; i++) {
7644 cls ^= anon_classes.At(i);
7645 error = Compiler::CompileAllFunctions(cls);
7646 if (!error.IsNull()) {
7647 return error.raw();
7648 }
7649 }
7650 } 7644 }
7651 return error.raw(); 7645 return error.raw();
7652 } 7646 }
7653 7647
7654 7648
7655 struct FpDiff { 7649 struct FpDiff {
7656 FpDiff(int32_t old_, int32_t new_): old_fp(old_), new_fp(new_) {} 7650 FpDiff(int32_t old_, int32_t new_): old_fp(old_), new_fp(new_) {}
7657 int32_t old_fp; 7651 int32_t old_fp;
7658 int32_t new_fp; 7652 int32_t new_fp;
7659 }; 7653 };
(...skipping 6963 matching lines...) Expand 10 before | Expand all | Expand 10 after
14623 } 14617 }
14624 14618
14625 14619
14626 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14620 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14627 stream->OpenObject(); 14621 stream->OpenObject();
14628 stream->CloseObject(); 14622 stream->CloseObject();
14629 } 14623 }
14630 14624
14631 14625
14632 } // namespace dart 14626 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698