Skip to content

Commit d3d605b

Browse files
authored
[FileCheck] Use move semantics instead of std::swap. NFC. (#123304)
This code was using a pre-move-semantics trick of using std::swap to avoid expensive vector copies.
1 parent 590e5e2 commit d3d605b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

llvm/lib/FileCheck/FileCheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,8 +1933,8 @@ bool FileCheck::readCheckFile(
19331933
}
19341934

19351935
// Okay, add the string we captured to the output vector and move on.
1936-
CheckStrings.emplace_back(P, UsedPrefix, PatternLoc);
1937-
std::swap(DagNotMatches, CheckStrings.back().DagNotStrings);
1936+
CheckStrings.emplace_back(std::move(P), UsedPrefix, PatternLoc,
1937+
std::move(DagNotMatches));
19381938
DagNotMatches = ImplicitNegativeChecks;
19391939
}
19401940

@@ -1963,8 +1963,8 @@ bool FileCheck::readCheckFile(
19631963
if (!DagNotMatches.empty()) {
19641964
CheckStrings.emplace_back(
19651965
Pattern(Check::CheckEOF, PatternContext.get(), LineNumber + 1),
1966-
*Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data()));
1967-
std::swap(DagNotMatches, CheckStrings.back().DagNotStrings);
1966+
*Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data()),
1967+
std::move(DagNotMatches));
19681968
}
19691969

19701970
return false;

llvm/lib/FileCheck/FileCheckImpl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,9 @@ struct FileCheckString {
837837
/// Hold the DAG/NOT strings occurring in the input file.
838838
std::vector<DagNotPrefixInfo> DagNotStrings;
839839

840-
FileCheckString(const Pattern &P, StringRef S, SMLoc L)
841-
: Pat(P), Prefix(S), Loc(L) {}
840+
FileCheckString(Pattern &&P, StringRef S, SMLoc L,
841+
std::vector<DagNotPrefixInfo> &&D)
842+
: Pat(std::move(P)), Prefix(S), Loc(L), DagNotStrings(std::move(D)) {}
842843

843844
/// Matches check string and its "not strings" and/or "dag strings".
844845
size_t Check(const SourceMgr &SM, StringRef Buffer, bool IsLabelScanMode,

0 commit comments

Comments
 (0)