[llvm] 7c80c4d - [MC] NFC. Avoid redundant copies when constructing StructFieldInfo
Ilya Biryukov via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 11 02:54:00 PDT 2022
Author: Ilya Biryukov
Date: 2022-08-11T11:53:24+02:00
New Revision: 7c80c4d67716308dc0f382be88bbe73dd293892c
URL: https://github.com/llvm/llvm-project/commit/7c80c4d67716308dc0f382be88bbe73dd293892c
DIFF: https://github.com/llvm/llvm-project/commit/7c80c4d67716308dc0f382be88bbe73dd293892c.diff
LOG: [MC] NFC. Avoid redundant copies when constructing StructFieldInfo
Follow-up after D131595, see comments in the review thread.
The intention of having two constructors was to minimize the copies of
`vector`, but a lack of `std::move` on the call site caused the wrong
constructor to be called.
Switched to a single constructor that accepts a value.
Accepting by value allows to have a single constructor and still decide
to copy or move on the call site.
Added:
Modified:
llvm/lib/MC/MCParser/MasmParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp
index 4f2a74e122657..517779863089a 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -168,8 +168,7 @@ struct StructFieldInfo {
StructInfo Structure;
StructFieldInfo() = default;
- StructFieldInfo(const std::vector<StructInitializer> &V, StructInfo S);
- StructFieldInfo(std::vector<StructInitializer> &&V, StructInfo S);
+ StructFieldInfo(std::vector<StructInitializer> V, StructInfo S);
};
class FieldInitializer {
@@ -218,15 +217,9 @@ struct FieldInfo {
FieldInfo(FieldType FT) : Contents(FT) {}
};
-StructFieldInfo::StructFieldInfo(const std::vector<StructInitializer> &V,
+StructFieldInfo::StructFieldInfo(std::vector<StructInitializer> V,
StructInfo S) {
- Initializers = V;
- Structure = S;
-}
-
-StructFieldInfo::StructFieldInfo(std::vector<StructInitializer> &&V,
- StructInfo S) {
- Initializers = V;
+ Initializers = std::move(V);
Structure = S;
}
@@ -290,7 +283,7 @@ FieldInitializer::FieldInitializer(SmallVector<APInt, 1> &&AsIntValues)
FieldInitializer::FieldInitializer(
std::vector<StructInitializer> &&Initializers, struct StructInfo Structure)
: FT(FT_STRUCT) {
- new (&StructInfo) StructFieldInfo(Initializers, Structure);
+ new (&StructInfo) StructFieldInfo(std::move(Initializers), Structure);
}
FieldInitializer::FieldInitializer(const FieldInitializer &Initializer)
More information about the llvm-commits
mailing list