Skip to content

Commit

Permalink
Merge #1634: [Core] prevector: named union and defaults vars initiali…
Browse files Browse the repository at this point in the history
…zation

30e975e Lift prevector default vals to the member declaration (random-zebra)
3217b2b Name union to prevent compiler warning (random-zebra)

Pull request description:

  Two simple additions to `prevector` class:
  - name the union, to prevent compiler warnings emitted by clang (from bitcoin#7146)
  - use non-static data member initializers for `_size` and `_union` (from bitcoin#14266)

ACKs for top commit:
  furszy:
    utACK 30e975e
  Fuzzbawls:
    utACK 30e975e

Tree-SHA512: f7a0dd55bbf2df0b9d0d72967ac00c476aebde936499cd3d1b5a7552aded6b7022c5a23c859eaa3599875f2c2c7bd737afdda3cd31db9d7e2c5dfdca7f0c9809
  • Loading branch information
random-zebra committed May 22, 2020
2 parents cadf9e6 + 30e975e commit e0239f8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/prevector.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ class prevector {
};

private:
size_type _size;
union {
size_type _size = 0;
union direct_or_indirect {
char direct[sizeof(T) * N];
struct {
size_type capacity;
char* indirect;
};
} _union;
} _union = {};

T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; }
const T* direct_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.direct) + pos; }
Expand Down Expand Up @@ -220,13 +220,13 @@ class prevector {
}
}

prevector() : _size(0), _union{{}} {}
prevector() {}

explicit prevector(size_type n) : prevector() {
explicit prevector(size_type n) {
resize(n);
}

explicit prevector(size_type n, const T& val = T()) : prevector() {
explicit prevector(size_type n, const T& val = T()) {
change_capacity(n);
while (size() < n) {
_size++;
Expand All @@ -235,7 +235,7 @@ class prevector {
}

template<typename InputIterator>
prevector(InputIterator first, InputIterator last) : prevector() {
prevector(InputIterator first, InputIterator last) {
size_type n = last - first;
change_capacity(n);
while (first != last) {
Expand All @@ -245,7 +245,7 @@ class prevector {
}
}

prevector(const prevector<N, T, Size, Diff>& other) : prevector() {
prevector(const prevector<N, T, Size, Diff>& other) {
change_capacity(other.size());
const_iterator it = other.begin();
while (it != other.end()) {
Expand All @@ -255,7 +255,7 @@ class prevector {
}
}

prevector(prevector<N, T, Size, Diff>&& other) : prevector() {
prevector(prevector<N, T, Size, Diff>&& other) {
swap(other);
}

Expand Down

0 comments on commit e0239f8

Please sign in to comment.