Merge "TypeHelpers.h: Don't underflow unsigned int"

This commit is contained in:
Nick Kralevich 2015-06-15 17:30:38 +00:00 committed by Gerrit Code Review
commit 7015b3be53

View file

@ -131,7 +131,8 @@ int compare_type(const TYPE& lhs, const TYPE& rhs) {
template<typename TYPE> inline template<typename TYPE> inline
void construct_type(TYPE* p, size_t n) { void construct_type(TYPE* p, size_t n) {
if (!traits<TYPE>::has_trivial_ctor) { if (!traits<TYPE>::has_trivial_ctor) {
while (n--) { while (n > 0) {
n--;
new(p++) TYPE; new(p++) TYPE;
} }
} }
@ -140,7 +141,8 @@ void construct_type(TYPE* p, size_t n) {
template<typename TYPE> inline template<typename TYPE> inline
void destroy_type(TYPE* p, size_t n) { void destroy_type(TYPE* p, size_t n) {
if (!traits<TYPE>::has_trivial_dtor) { if (!traits<TYPE>::has_trivial_dtor) {
while (n--) { while (n > 0) {
n--;
p->~TYPE(); p->~TYPE();
p++; p++;
} }
@ -150,7 +152,8 @@ void destroy_type(TYPE* p, size_t n) {
template<typename TYPE> inline template<typename TYPE> inline
void copy_type(TYPE* d, const TYPE* s, size_t n) { void copy_type(TYPE* d, const TYPE* s, size_t n) {
if (!traits<TYPE>::has_trivial_copy) { if (!traits<TYPE>::has_trivial_copy) {
while (n--) { while (n > 0) {
n--;
new(d) TYPE(*s); new(d) TYPE(*s);
d++, s++; d++, s++;
} }
@ -162,12 +165,14 @@ void copy_type(TYPE* d, const TYPE* s, size_t n) {
template<typename TYPE> inline template<typename TYPE> inline
void splat_type(TYPE* where, const TYPE* what, size_t n) { void splat_type(TYPE* where, const TYPE* what, size_t n) {
if (!traits<TYPE>::has_trivial_copy) { if (!traits<TYPE>::has_trivial_copy) {
while (n--) { while (n > 0) {
n--;
new(where) TYPE(*what); new(where) TYPE(*what);
where++; where++;
} }
} else { } else {
while (n--) { while (n > 0) {
n--;
*where++ = *what; *where++ = *what;
} }
} }
@ -182,7 +187,8 @@ void move_forward_type(TYPE* d, const TYPE* s, size_t n = 1) {
} else { } else {
d += n; d += n;
s += n; s += n;
while (n--) { while (n > 0) {
n--;
--d, --s; --d, --s;
if (!traits<TYPE>::has_trivial_copy) { if (!traits<TYPE>::has_trivial_copy) {
new(d) TYPE(*s); new(d) TYPE(*s);
@ -203,7 +209,8 @@ void move_backward_type(TYPE* d, const TYPE* s, size_t n = 1) {
{ {
memmove(d,s,n*sizeof(TYPE)); memmove(d,s,n*sizeof(TYPE));
} else { } else {
while (n--) { while (n > 0) {
n--;
if (!traits<TYPE>::has_trivial_copy) { if (!traits<TYPE>::has_trivial_copy) {
new(d) TYPE(*s); new(d) TYPE(*s);
} else { } else {