summaryrefslogtreecommitdiff
path: root/src/support/small_vector.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-09-17 16:18:14 -0700
committerGitHub <noreply@github.com>2024-09-17 16:18:14 -0700
commita99b48a4502628d46683fc85697251db3a8069b0 (patch)
tree0c834bb0d9a20ca4472faa726a3cc81afc71bc8e /src/support/small_vector.h
parentbdc7ce0fbb2373d0ce666782fdce88f3bd8d6f17 (diff)
downloadbinaryen-a99b48a4502628d46683fc85697251db3a8069b0.tar.gz
binaryen-a99b48a4502628d46683fc85697251db3a8069b0.tar.bz2
binaryen-a99b48a4502628d46683fc85697251db3a8069b0.zip
[NFC] Make the GCData constructor a move constructor (#6946)
This avoids creating a large Literals (SmallVector of Literal) and then copying it. All the places that construct GCData do not need the Literals afterwards. This gives a 7% speedup on the --precompute benchmark from #6931
Diffstat (limited to 'src/support/small_vector.h')
-rw-r--r--src/support/small_vector.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/support/small_vector.h b/src/support/small_vector.h
index 503dfbd5c..dd0370554 100644
--- a/src/support/small_vector.h
+++ b/src/support/small_vector.h
@@ -65,6 +65,12 @@ public:
using value_type = T;
SmallVector() {}
+ SmallVector(const SmallVector<T, N>& other)
+ : usedFixed(other.usedFixed), fixed(other.fixed), flexible(other.flexible) {
+ }
+ SmallVector(SmallVector<T, N>&& other)
+ : usedFixed(other.usedFixed), fixed(std::move(other.fixed)),
+ flexible(std::move(other.flexible)) {}
SmallVector(std::initializer_list<T> init) {
for (T item : init) {
push_back(item);
@@ -72,6 +78,20 @@ public:
}
SmallVector(size_t initialSize) { resize(initialSize); }
+ SmallVector<T, N>& operator=(const SmallVector<T, N>& other) {
+ usedFixed = other.usedFixed;
+ fixed = other.fixed;
+ flexible = other.flexible;
+ return *this;
+ }
+
+ SmallVector<T, N>& operator=(SmallVector<T, N>&& other) {
+ usedFixed = other.usedFixed;
+ fixed = std::move(other.fixed);
+ flexible = std::move(other.flexible);
+ return *this;
+ }
+
T& operator[](size_t i) {
if (i < N) {
return fixed[i];