mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-15 07:03:40 +01:00
Merge #14651: Refactor: Fix compiler warning in prevector.h
76e13b586f warnings: Compiler warning on memset usage for non-trivial type (Lenny Maiorani)
Pull request description:
Fixing warnings reported by GCC: memset of non-trivial type
Tree-SHA512: 357aeac60acfb922851daaf0bd8d4b81e377da7c9b31c2942b54cfdd4129dae61e577fc0a6aa430348cb07abd16ae32f986a64dbb2c1d90ec148f53e7451a229
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -198,22 +199,11 @@ private:
|
|||||||
const T* item_ptr(difference_type pos) const { return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); }
|
const T* item_ptr(difference_type pos) const { return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); }
|
||||||
|
|
||||||
void fill(T* dst, ptrdiff_t count) {
|
void fill(T* dst, ptrdiff_t count) {
|
||||||
if (IS_TRIVIALLY_CONSTRUCTIBLE<T>::value) {
|
std::fill_n(dst, count, T{});
|
||||||
// The most common use of prevector is where T=unsigned char. For
|
|
||||||
// trivially constructible types, we can use memset() to avoid
|
|
||||||
// looping.
|
|
||||||
::memset(dst, 0, count * sizeof(T));
|
|
||||||
} else {
|
|
||||||
for (auto i = 0; i < count; ++i) {
|
|
||||||
new(static_cast<void*>(dst + i)) T();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill(T* dst, ptrdiff_t count, const T& value) {
|
void fill(T* dst, ptrdiff_t count, const T& value) {
|
||||||
for (auto i = 0; i < count; ++i) {
|
std::fill_n(dst, count, value);
|
||||||
new(static_cast<void*>(dst + i)) T(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIterator>
|
template<typename InputIterator>
|
||||||
|
|||||||
Reference in New Issue
Block a user