Chromium Code Reviews| Index: runtime/vm/object.cc |
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
| index 29725c72b3d739c3aeb5639516455f1558347c89..0fc7cd49cf81a6a5eb25de2f6d5348d0c4735521 100644 |
| --- a/runtime/vm/object.cc |
| +++ b/runtime/vm/object.cc |
| @@ -6789,6 +6789,24 @@ void Library::AddClass(const Class& cls) const { |
| cls.set_library(*this); |
| } |
| +static void AddScriptIfUnique(const GrowableObjectArray& scripts, |
| + Script& candidate) { |
| + Script& script_obj = Script::Handle(); |
|
siva
2013/09/06 15:33:51
Move the handle creation below the null check so w
|
| + if (candidate.IsNull()) |
| + return; |
| + if (candidate.raw() == Object::null()) |
| + return; |
|
siva
2013/09/06 15:33:51
Seems like duplicate checks:
candidate.IsNull() i
|
| + |
| + for (int i = 0; i < scripts.Length(); i++) { |
| + script_obj ^= scripts.At(i); |
| + if (script_obj.raw() == candidate.raw()) { |
| + // We already have a reference to this script. |
| + return; |
| + } |
| + } |
| + // Add script to the list of scripts. |
| + scripts.Add(candidate); |
| +} |
| RawArray* Library::LoadedScripts() const { |
| // We compute the list of loaded scripts lazily. The result is |
| @@ -6799,13 +6817,19 @@ RawArray* Library::LoadedScripts() const { |
| GrowableObjectArray::Handle(GrowableObjectArray::New(8)); |
| Object& entry = Object::Handle(); |
| Class& cls = Class::Handle(); |
| + Class& patch_cls = Class::Handle(); |
| Script& owner_script = Script::Handle(); |
| + Script& patch_script = Script::Handle(); |
| DictionaryIterator it(*this); |
| - Script& script_obj = Script::Handle(); |
| while (it.HasNext()) { |
| entry = it.GetNext(); |
| if (entry.IsClass()) { |
| owner_script = Class::Cast(entry).script(); |
| + patch_cls = Class::Cast(entry).patch_class(); |
| + if (!patch_cls.IsNull()) { |
| + patch_script = patch_cls.script(); |
| + AddScriptIfUnique(scripts, patch_script); |
| + } |
| } else if (entry.IsFunction()) { |
| owner_script = Function::Cast(entry).script(); |
| } else if (entry.IsField()) { |
| @@ -6814,22 +6838,7 @@ RawArray* Library::LoadedScripts() const { |
| } else { |
| continue; |
| } |
| - if (owner_script.IsNull()) { |
| - continue; |
| - } |
| - bool is_unique = true; |
| - for (int i = 0; i < scripts.Length(); i++) { |
| - script_obj ^= scripts.At(i); |
| - if (script_obj.raw() == owner_script.raw()) { |
| - // We already have a reference to this script. |
| - is_unique = false; |
| - break; |
| - } |
| - } |
| - if (is_unique) { |
| - // Add script to the list of scripts. |
| - scripts.Add(owner_script); |
| - } |
| + AddScriptIfUnique(scripts, owner_script); |
| } |
| // Create the array of scripts and cache it in loaded_scripts_. |