diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp b/clang/lib/Lex/DependencyDirectivesScanner.cpp index ccf80c4a9f57..430f46d0ba7f 100644 --- a/clang/lib/Lex/DependencyDirectivesScanner.cpp +++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp @@ -1212,6 +1212,11 @@ ModuleUnitKind clang::scanInputForCXX20ModuleUnit(StringRef Source) { } bool clang::isPreprocessedModuleFile(StringRef Source) { + // Fast path: a file without "__preprocessed_" has neither directive. + // Skipping the line-by-line walk speeds up the scan. + if (!Source.contains("__preprocessed_")) + return false; + const char *First = Source.begin(); const char *const End = Source.end();