@@ -679,10 +679,7 @@ function flush_queued_root_effects(root_effects) {
679
679
effect . f ^= CLEAN ;
680
680
}
681
681
682
- /** @type {Effect[] } */
683
- var collected_effects = [ ] ;
684
-
685
- process_effects ( effect , collected_effects ) ;
682
+ var collected_effects = process_effects ( effect ) ;
686
683
flush_queued_effects ( collected_effects ) ;
687
684
}
688
685
} finally {
@@ -783,48 +780,47 @@ export function schedule_effect(signal) {
783
780
* effects to be flushed.
784
781
*
785
782
* @param {Effect } effect
786
- * @param {Effect[] } collected_effects
787
- * @returns {void }
783
+ * @returns {Effect[] }
788
784
*/
789
- function process_effects ( effect , collected_effects ) {
790
- var current_effect = effect . first ;
785
+ function process_effects ( effect ) {
786
+ /** @type { Effect[] } */
791
787
var effects = [ ] ;
792
788
789
+ var current_effect = effect . first ;
790
+
793
791
main_loop: while ( current_effect !== null ) {
794
792
var flags = current_effect . f ;
795
793
var is_branch = ( flags & BRANCH_EFFECT ) !== 0 ;
796
794
var is_skippable_branch = is_branch && ( flags & CLEAN ) !== 0 ;
797
795
var sibling = current_effect . next ;
798
796
799
797
if ( ! is_skippable_branch && ( flags & INERT ) === 0 ) {
800
- if ( ( flags & RENDER_EFFECT ) !== 0 ) {
801
- if ( is_branch ) {
802
- current_effect . f ^= CLEAN ;
803
- } else {
804
- // Ensure we set the effect to be the active reaction
805
- // to ensure that unowned deriveds are correctly tracked
806
- // because we're flushing the current effect
807
- var previous_active_reaction = active_reaction ;
808
- try {
809
- active_reaction = current_effect ;
810
- if ( check_dirtiness ( current_effect ) ) {
811
- update_effect ( current_effect ) ;
812
- }
813
- } catch ( error ) {
814
- handle_error ( error , current_effect , null , current_effect . ctx ) ;
815
- } finally {
816
- active_reaction = previous_active_reaction ;
798
+ if ( ( flags & EFFECT ) !== 0 ) {
799
+ effects . push ( current_effect ) ;
800
+ } else if ( is_branch ) {
801
+ current_effect . f ^= CLEAN ;
802
+ } else {
803
+ // Ensure we set the effect to be the active reaction
804
+ // to ensure that unowned deriveds are correctly tracked
805
+ // because we're flushing the current effect
806
+ var previous_active_reaction = active_reaction ;
807
+ try {
808
+ active_reaction = current_effect ;
809
+ if ( check_dirtiness ( current_effect ) ) {
810
+ update_effect ( current_effect ) ;
817
811
}
812
+ } catch ( error ) {
813
+ handle_error ( error , current_effect , null , current_effect . ctx ) ;
814
+ } finally {
815
+ active_reaction = previous_active_reaction ;
818
816
}
817
+ }
819
818
820
- var child = current_effect . first ;
819
+ var child = current_effect . first ;
821
820
822
- if ( child !== null ) {
823
- current_effect = child ;
824
- continue ;
825
- }
826
- } else if ( ( flags & EFFECT ) !== 0 ) {
827
- effects . push ( current_effect ) ;
821
+ if ( child !== null ) {
822
+ current_effect = child ;
823
+ continue ;
828
824
}
829
825
}
830
826
@@ -847,13 +843,7 @@ function process_effects(effect, collected_effects) {
847
843
current_effect = sibling ;
848
844
}
849
845
850
- // We might be dealing with many effects here, far more than can be spread into
851
- // an array push call (callstack overflow). So let's deal with each effect in a loop.
852
- for ( var i = 0 ; i < effects . length ; i ++ ) {
853
- child = effects [ i ] ;
854
- collected_effects . push ( child ) ;
855
- process_effects ( child , collected_effects ) ;
856
- }
846
+ return effects ;
857
847
}
858
848
859
849
/**
0 commit comments