Skip to content

Commit 119a728

Browse files
committed
[clang-format][NFC] Remove redundant calls to guessIsObjC()
Running clang-format on the following input ``` int lambdas() { return [&] { return [&] { return [&] { return [&] { return [&] { return [&] { return [&] { return 3; } (); } (); } (); } (); } (); } (); } (); } ``` will finish instantly if you pass clang-format a .cpp input with this content, but hang for tens of seconds if you pass the same via stdin or a .h file. Adding some debug statements showed that guessIsObjC was getting called tens of millions of times in a manner that scales very rapidly with the amount of nesting (if clang-format just takes a few seconds with that input passed on stdin, try adding a couple more levels of nesting). This change moves the recursive guessIsObjC call one level of nesting out of an inner loop whose iterations don't affect the input to the recursive call. This resolves the performance issue. Authored-by: davidvc1 and Uran198 Differential Revision: https://reviews.llvm.org/D114837 Differential Revision: https://reviews.llvm.org/D47515
1 parent 1cbe26d commit 119a728

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clang/lib/Format/Format.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,9 +2948,9 @@ class ObjCHeaderStyleGuesser : public TokenAnalyzer {
29482948
<< getTokenTypeName(FormatTok->getType()) << "\n");
29492949
return true;
29502950
}
2951-
if (guessIsObjC(SourceManager, Line->Children, Keywords))
2952-
return true;
29532951
}
2952+
if (guessIsObjC(SourceManager, Line->Children, Keywords))
2953+
return true;
29542954
}
29552955
return false;
29562956
}

0 commit comments

Comments
 (0)