diff options
author | Alon Zakai <azakai@google.com> | 2024-09-17 16:18:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-17 16:18:14 -0700 |
commit | a99b48a4502628d46683fc85697251db3a8069b0 (patch) | |
tree | 0c834bb0d9a20ca4472faa726a3cc81afc71bc8e /src/support/small_vector.h | |
parent | bdc7ce0fbb2373d0ce666782fdce88f3bd8d6f17 (diff) | |
download | binaryen-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.h | 20 |
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]; |