Changeset View
Changeset View
Standalone View
Standalone View
src/prevector.h
Show First 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | T *item_ptr(difference_type pos) { | ||||
return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); | return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); | ||||
} | } | ||||
const T *item_ptr(difference_type pos) const { | const T *item_ptr(difference_type pos) const { | ||||
return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); | 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) { | if (IS_TRIVIALLY_CONSTRUCTIBLE<T>::value) { | ||||
// The most common use of prevector is where T=unsigned char. For | // The most common use of prevector is where T=uint8_t. For | ||||
// trivially constructible types, we can use memset() to avoid | // trivially constructible types, we can use memset() to avoid | ||||
// looping. | // looping. | ||||
::memset(dst, 0, count * sizeof(T)); | ::memset(dst, 0, count * sizeof(T)); | ||||
} else { | } else { | ||||
for (auto i = 0; i < count; ++i) { | for (auto i = 0; i < count; ++i) { | ||||
new (static_cast<void *>(dst + i)) T(); | new (static_cast<void *>(dst + i)) T(); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 293 Lines • Show Last 20 Lines |