forked from OctaForge/libostd
use IsPOD rather than !IsClass to decide whether to memcpy etc.
This commit is contained in:
parent
89bab3362b
commit
cca0a62d34
|
@ -78,7 +78,7 @@ namespace octa {
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
if (p_cap > 0) {
|
if (p_cap > 0) {
|
||||||
if (octa::IsClass<T>::value) {
|
if (!octa::IsPOD<T>::value) {
|
||||||
T *cur = p_buf, *last = p_buf + p_len;
|
T *cur = p_buf, *last = p_buf + p_len;
|
||||||
while (cur != last) (*cur++).~T();
|
while (cur != last) (*cur++).~T();
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ namespace octa {
|
||||||
if (this == &v) return *this;
|
if (this == &v) return *this;
|
||||||
|
|
||||||
if (p_cap >= v.p_cap) {
|
if (p_cap >= v.p_cap) {
|
||||||
if (octa::IsClass<T>::value) {
|
if (!octa::IsPOD<T>::value) {
|
||||||
T *cur = p_buf, *last = p_buf + p_len;
|
T *cur = p_buf, *last = p_buf + p_len;
|
||||||
while (cur != last) (*cur++).~T();
|
while (cur != last) (*cur++).~T();
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ namespace octa {
|
||||||
p_buf = (T *)new uchar[p_cap * sizeof(T)];
|
p_buf = (T *)new uchar[p_cap * sizeof(T)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!octa::IsClass<T>::value) {
|
if (octa::IsPOD<T>::value) {
|
||||||
memcpy(p_buf, v.p_buf, p_len * sizeof(T));
|
memcpy(p_buf, v.p_buf, p_len * sizeof(T));
|
||||||
} else {
|
} else {
|
||||||
T *cur = p_buf, *last = p_buf + p_len;
|
T *cur = p_buf, *last = p_buf + p_len;
|
||||||
|
@ -129,7 +129,7 @@ namespace octa {
|
||||||
size_t len = p_len;
|
size_t len = p_len;
|
||||||
reserve(n);
|
reserve(n);
|
||||||
p_len = n;
|
p_len = n;
|
||||||
if (!octa::IsClass<T>::value) {
|
if (octa::IsPOD<T>::value) {
|
||||||
for (size_t i = len; i < p_len; ++i) {
|
for (size_t i = len; i < p_len; ++i) {
|
||||||
p_buf[i] = T(v);
|
p_buf[i] = T(v);
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ namespace octa {
|
||||||
}
|
}
|
||||||
T *tmp = (T *)new uchar[p_cap * sizeof(T)];
|
T *tmp = (T *)new uchar[p_cap * sizeof(T)];
|
||||||
if (oc > 0) {
|
if (oc > 0) {
|
||||||
if (!octa::IsClass<T>::value) {
|
if (octa::IsPOD<T>::value) {
|
||||||
memcpy(tmp, p_buf, p_len * sizeof(T));
|
memcpy(tmp, p_buf, p_len * sizeof(T));
|
||||||
} else {
|
} else {
|
||||||
T *cur = p_buf, *tcur = tmp, *last = tmp + p_len;
|
T *cur = p_buf, *tcur = tmp, *last = tmp + p_len;
|
||||||
|
@ -195,7 +195,7 @@ namespace octa {
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop() {
|
void pop() {
|
||||||
if (octa::IsClass<T>::value) {
|
if (!octa::IsPOD<T>::value) {
|
||||||
p_buf[--p_len].~T();
|
p_buf[--p_len].~T();
|
||||||
} else {
|
} else {
|
||||||
--p_len;
|
--p_len;
|
||||||
|
|
Loading…
Reference in a new issue