Skip to content

Commit ae32806

Browse files
committed
Merge #14651: Refactor: Fix compiler warning in prevector.h
76e13b5 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
2 parents edc7152 + 76e13b5 commit ae32806

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/prevector.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <stdint.h>
1111
#include <string.h>
1212

13+
#include <algorithm>
1314
#include <cstddef>
1415
#include <iterator>
1516
#include <type_traits>
@@ -198,22 +199,11 @@ class prevector {
198199
const T* item_ptr(difference_type pos) const { return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); }
199200

200201
void fill(T* dst, ptrdiff_t count) {
201-
if (IS_TRIVIALLY_CONSTRUCTIBLE<T>::value) {
202-
// The most common use of prevector is where T=unsigned char. For
203-
// trivially constructible types, we can use memset() to avoid
204-
// looping.
205-
::memset(dst, 0, count * sizeof(T));
206-
} else {
207-
for (auto i = 0; i < count; ++i) {
208-
new(static_cast<void*>(dst + i)) T();
209-
}
210-
}
202+
std::fill_n(dst, count, T{});
211203
}
212204

213205
void fill(T* dst, ptrdiff_t count, const T& value) {
214-
for (auto i = 0; i < count; ++i) {
215-
new(static_cast<void*>(dst + i)) T(value);
216-
}
206+
std::fill_n(dst, count, value);
217207
}
218208

219209
template<typename InputIterator>

0 commit comments

Comments
 (0)