OLD | NEW |
---|---|
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 6771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6782 dict.SetAt(index, obj); | 6782 dict.SetAt(index, obj); |
6783 } | 6783 } |
6784 | 6784 |
6785 | 6785 |
6786 void Library::AddClass(const Class& cls) const { | 6786 void Library::AddClass(const Class& cls) const { |
6787 AddObject(cls, String::Handle(cls.Name())); | 6787 AddObject(cls, String::Handle(cls.Name())); |
6788 // Link class to this library. | 6788 // Link class to this library. |
6789 cls.set_library(*this); | 6789 cls.set_library(*this); |
6790 } | 6790 } |
6791 | 6791 |
6792 static void AddScriptIfUnique(const GrowableObjectArray& scripts, | |
6793 Script& candidate) { | |
6794 Script& script_obj = Script::Handle(); | |
siva
2013/09/06 15:33:51
Move the handle creation below the null check so w
| |
6795 if (candidate.IsNull()) | |
6796 return; | |
6797 if (candidate.raw() == Object::null()) | |
6798 return; | |
siva
2013/09/06 15:33:51
Seems like duplicate checks:
candidate.IsNull() i
| |
6799 | |
6800 for (int i = 0; i < scripts.Length(); i++) { | |
6801 script_obj ^= scripts.At(i); | |
6802 if (script_obj.raw() == candidate.raw()) { | |
6803 // We already have a reference to this script. | |
6804 return; | |
6805 } | |
6806 } | |
6807 // Add script to the list of scripts. | |
6808 scripts.Add(candidate); | |
6809 } | |
6792 | 6810 |
6793 RawArray* Library::LoadedScripts() const { | 6811 RawArray* Library::LoadedScripts() const { |
6794 // We compute the list of loaded scripts lazily. The result is | 6812 // We compute the list of loaded scripts lazily. The result is |
6795 // cached in loaded_scripts_. | 6813 // cached in loaded_scripts_. |
6796 if (loaded_scripts() == Array::null()) { | 6814 if (loaded_scripts() == Array::null()) { |
6797 // Iterate over the library dictionary and collect all scripts. | 6815 // Iterate over the library dictionary and collect all scripts. |
6798 const GrowableObjectArray& scripts = | 6816 const GrowableObjectArray& scripts = |
6799 GrowableObjectArray::Handle(GrowableObjectArray::New(8)); | 6817 GrowableObjectArray::Handle(GrowableObjectArray::New(8)); |
6800 Object& entry = Object::Handle(); | 6818 Object& entry = Object::Handle(); |
6801 Class& cls = Class::Handle(); | 6819 Class& cls = Class::Handle(); |
6820 Class& patch_cls = Class::Handle(); | |
6802 Script& owner_script = Script::Handle(); | 6821 Script& owner_script = Script::Handle(); |
6822 Script& patch_script = Script::Handle(); | |
6803 DictionaryIterator it(*this); | 6823 DictionaryIterator it(*this); |
6804 Script& script_obj = Script::Handle(); | |
6805 while (it.HasNext()) { | 6824 while (it.HasNext()) { |
6806 entry = it.GetNext(); | 6825 entry = it.GetNext(); |
6807 if (entry.IsClass()) { | 6826 if (entry.IsClass()) { |
6808 owner_script = Class::Cast(entry).script(); | 6827 owner_script = Class::Cast(entry).script(); |
6828 patch_cls = Class::Cast(entry).patch_class(); | |
6829 if (!patch_cls.IsNull()) { | |
6830 patch_script = patch_cls.script(); | |
6831 AddScriptIfUnique(scripts, patch_script); | |
6832 } | |
6809 } else if (entry.IsFunction()) { | 6833 } else if (entry.IsFunction()) { |
6810 owner_script = Function::Cast(entry).script(); | 6834 owner_script = Function::Cast(entry).script(); |
6811 } else if (entry.IsField()) { | 6835 } else if (entry.IsField()) { |
6812 cls = Field::Cast(entry).owner(); | 6836 cls = Field::Cast(entry).owner(); |
6813 owner_script = cls.script(); | 6837 owner_script = cls.script(); |
6814 } else { | 6838 } else { |
6815 continue; | 6839 continue; |
6816 } | 6840 } |
6817 if (owner_script.IsNull()) { | 6841 AddScriptIfUnique(scripts, owner_script); |
6818 continue; | |
6819 } | |
6820 bool is_unique = true; | |
6821 for (int i = 0; i < scripts.Length(); i++) { | |
6822 script_obj ^= scripts.At(i); | |
6823 if (script_obj.raw() == owner_script.raw()) { | |
6824 // We already have a reference to this script. | |
6825 is_unique = false; | |
6826 break; | |
6827 } | |
6828 } | |
6829 if (is_unique) { | |
6830 // Add script to the list of scripts. | |
6831 scripts.Add(owner_script); | |
6832 } | |
6833 } | 6842 } |
6834 | 6843 |
6835 // Create the array of scripts and cache it in loaded_scripts_. | 6844 // Create the array of scripts and cache it in loaded_scripts_. |
6836 const Array& scripts_array = Array::Handle(Array::MakeArray(scripts)); | 6845 const Array& scripts_array = Array::Handle(Array::MakeArray(scripts)); |
6837 StorePointer(&raw_ptr()->loaded_scripts_, scripts_array.raw()); | 6846 StorePointer(&raw_ptr()->loaded_scripts_, scripts_array.raw()); |
6838 } | 6847 } |
6839 return loaded_scripts(); | 6848 return loaded_scripts(); |
6840 } | 6849 } |
6841 | 6850 |
6842 | 6851 |
(...skipping 8085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14928 } | 14937 } |
14929 | 14938 |
14930 | 14939 |
14931 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14940 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
14932 stream->OpenObject(); | 14941 stream->OpenObject(); |
14933 stream->CloseObject(); | 14942 stream->CloseObject(); |
14934 } | 14943 } |
14935 | 14944 |
14936 | 14945 |
14937 } // namespace dart | 14946 } // namespace dart |
OLD | NEW |