OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/loader/modulescript/ModuleTreeLinker.h" | 5 #include "core/loader/modulescript/ModuleTreeLinker.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptModule.h" | 7 #include "bindings/core/v8/ScriptModule.h" |
8 #include "core/dom/AncestorList.h" | 8 #include "core/dom/AncestorList.h" |
9 #include "core/dom/ModuleScript.h" | 9 #include "core/dom/ModuleScript.h" |
10 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" | 10 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 | 444 |
445 // Step 4. While stack is not empty: | 445 // Step 4. While stack is not empty: |
446 while (!stack.IsEmpty()) { | 446 while (!stack.IsEmpty()) { |
447 // Step 4.1. Let current the result of popping from stack. | 447 // Step 4.1. Let current the result of popping from stack. |
448 ModuleScript* current = stack.TakeFirst(); | 448 ModuleScript* current = stack.TakeFirst(); |
449 | 449 |
450 // Step 4.2. Assert: current is a module script (i.e., it is not "fetching" | 450 // Step 4.2. Assert: current is a module script (i.e., it is not "fetching" |
451 // or null). | 451 // or null). |
452 DCHECK(current); | 452 DCHECK(current); |
453 | 453 |
| 454 // [nospec, optimization] |
| 455 // We can safely skip recursing into the descendants if the module graph |
| 456 // node status is "instantiated". The sub-graph is guaranteed to be all |
| 457 // "instantiated", thus never would end up in the "uninstantiated set". |
| 458 if (current->InstantiationState() == |
| 459 ModuleInstantiationState::kInstantiated) |
| 460 continue; |
| 461 |
454 // Step 4.3. If inclusive descendants and stack both do not contain current, | 462 // Step 4.3. If inclusive descendants and stack both do not contain current, |
455 // then: | 463 // then: |
456 if (inclusive_descendants.Contains(current)) | 464 if (inclusive_descendants.Contains(current)) |
457 continue; | 465 continue; |
458 if (std::find(stack.begin(), stack.end(), current) != stack.end()) | 466 if (std::find(stack.begin(), stack.end(), current) != stack.end()) |
459 continue; | 467 continue; |
460 | 468 |
461 // Step 4.3.1. Append current to inclusive descendants. | 469 // Step 4.3.1. Append current to inclusive descendants. |
462 inclusive_descendants.insert(current); | 470 inclusive_descendants.insert(current); |
463 | 471 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 HeapHashSet<Member<ModuleScript>> uninstantiated_set; | 520 HeapHashSet<Member<ModuleScript>> uninstantiated_set; |
513 for (const auto& script : inclusive_descendants) { | 521 for (const auto& script : inclusive_descendants) { |
514 if (script->InstantiationState() == | 522 if (script->InstantiationState() == |
515 ModuleInstantiationState::kUninstantiated) | 523 ModuleInstantiationState::kUninstantiated) |
516 uninstantiated_set.insert(script); | 524 uninstantiated_set.insert(script); |
517 } | 525 } |
518 return uninstantiated_set; | 526 return uninstantiated_set; |
519 } | 527 } |
520 | 528 |
521 } // namespace blink | 529 } // namespace blink |
OLD | NEW |