ivanmurashko updated this revision to Diff 406411. ivanmurashko added a comment.
There are some changes: - unit test for HeaderIncludes was added - lit test for clangd was removed - Solution uses std::list instead of copying by value Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D118755/new/ https://reviews.llvm.org/D118755 Files: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h clang/unittests/Tooling/HeaderIncludesTest.cpp Index: clang/unittests/Tooling/HeaderIncludesTest.cpp =================================================================== --- clang/unittests/Tooling/HeaderIncludesTest.cpp +++ clang/unittests/Tooling/HeaderIncludesTest.cpp @@ -51,6 +51,15 @@ EXPECT_EQ(Expected, insert(Code, "\"a.h\"")); } +TEST_F(HeaderIncludesTest, RepeatedIncludes) { + std::string Code; + for (int i = 0; i < 100; ++i) { + Code += "#include \"a.h\"\n"; + } + std::string Expected = Code + "#include \"a2.h\"\n"; + EXPECT_EQ(Expected, insert(Code, "\"a2.h\"")); +} + TEST_F(HeaderIncludesTest, NoExistingIncludeWithDefine) { std::string Code = "#ifndef A_H\n" "#define A_H\n" Index: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h =================================================================== --- clang/include/clang/Tooling/Inclusions/HeaderIncludes.h +++ clang/include/clang/Tooling/Inclusions/HeaderIncludes.h @@ -14,6 +14,7 @@ #include "clang/Tooling/Inclusions/IncludeStyle.h" #include "llvm/Support/Path.h" #include "llvm/Support/Regex.h" +#include <list> #include <unordered_map> namespace clang { @@ -97,7 +98,7 @@ // Map from include name (quotation trimmed) to a list of existing includes // (in case there are more than one) with the name in the current file. <x> // and "x" will be treated as the same header when deleting #includes. - llvm::StringMap<llvm::SmallVector<Include, 1>> ExistingIncludes; + llvm::StringMap<std::list<Include>> ExistingIncludes; /// Map from priorities of #include categories to all #includes in the same /// category. This is used to find #includes of the same category when
Index: clang/unittests/Tooling/HeaderIncludesTest.cpp =================================================================== --- clang/unittests/Tooling/HeaderIncludesTest.cpp +++ clang/unittests/Tooling/HeaderIncludesTest.cpp @@ -51,6 +51,15 @@ EXPECT_EQ(Expected, insert(Code, "\"a.h\"")); } +TEST_F(HeaderIncludesTest, RepeatedIncludes) { + std::string Code; + for (int i = 0; i < 100; ++i) { + Code += "#include \"a.h\"\n"; + } + std::string Expected = Code + "#include \"a2.h\"\n"; + EXPECT_EQ(Expected, insert(Code, "\"a2.h\"")); +} + TEST_F(HeaderIncludesTest, NoExistingIncludeWithDefine) { std::string Code = "#ifndef A_H\n" "#define A_H\n" Index: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h =================================================================== --- clang/include/clang/Tooling/Inclusions/HeaderIncludes.h +++ clang/include/clang/Tooling/Inclusions/HeaderIncludes.h @@ -14,6 +14,7 @@ #include "clang/Tooling/Inclusions/IncludeStyle.h" #include "llvm/Support/Path.h" #include "llvm/Support/Regex.h" +#include <list> #include <unordered_map> namespace clang { @@ -97,7 +98,7 @@ // Map from include name (quotation trimmed) to a list of existing includes // (in case there are more than one) with the name in the current file. <x> // and "x" will be treated as the same header when deleting #includes. - llvm::StringMap<llvm::SmallVector<Include, 1>> ExistingIncludes; + llvm::StringMap<std::list<Include>> ExistingIncludes; /// Map from priorities of #include categories to all #includes in the same /// category. This is used to find #includes of the same category when
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits