File tree Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -1802,20 +1802,29 @@ bool TopLevelCodeScope::isCurrent() const {
1802
1802
return bodyWhenLastExpanded == decl->getBody ();
1803
1803
}
1804
1804
1805
+ // Try to avoid the work of counting
1806
+ static const bool assumeVarsDoNotGetAdded = true ;
1807
+
1808
+ static unsigned countVars (const PatternBindingEntry &entry) {
1809
+ unsigned varCount = 0 ;
1810
+ entry.getPattern ()->forEachVariable ([&](VarDecl *) { ++varCount; });
1811
+ return varCount;
1812
+ }
1813
+
1805
1814
void PatternEntryDeclScope::beCurrent () {
1806
1815
initWhenLastExpanded = getPatternEntry ().getOriginalInit ();
1807
- unsigned varCount = 0 ;
1808
- getPatternEntry ().getPattern ()->forEachVariable (
1809
- [&](VarDecl *) { ++varCount; });
1810
- varCountWhenLastExpanded = varCount;
1816
+ if (assumeVarsDoNotGetAdded && varCountWhenLastExpanded)
1817
+ return ;
1818
+ varCountWhenLastExpanded = countVars (getPatternEntry ());
1811
1819
}
1812
1820
bool PatternEntryDeclScope::isCurrent () const {
1813
1821
if (initWhenLastExpanded != getPatternEntry ().getOriginalInit ())
1814
1822
return false ;
1815
- unsigned varCount = 0 ;
1816
- getPatternEntry ().getPattern ()->forEachVariable (
1817
- [&](VarDecl *) { ++varCount; });
1818
- return varCount == varCountWhenLastExpanded;
1823
+ if (assumeVarsDoNotGetAdded && varCountWhenLastExpanded) {
1824
+ assert (varCountWhenLastExpanded == countVars (getPatternEntry ()));
1825
+ return true ;
1826
+ }
1827
+ return countVars (getPatternEntry ()) == varCountWhenLastExpanded;
1819
1828
}
1820
1829
1821
1830
void WholeClosureScope::beCurrent () {
You can’t perform that action at this time.
0 commit comments