forked from OctaForge/libostd
vector: do not free buffer in copy assignment unless necessary
parent
ed24618061
commit
7e61799f8b
|
@ -102,21 +102,9 @@ namespace octa {
|
||||||
&& IsNothrowCopyConstructible<T>::value
|
&& IsNothrowCopyConstructible<T>::value
|
||||||
) {
|
) {
|
||||||
if (this == &v) return *this;
|
if (this == &v) return *this;
|
||||||
|
clear();
|
||||||
if (p_cap >= v.p_cap) {
|
reserve(v.p_cap);
|
||||||
if (!octa::IsPod<T>()) {
|
p_len = v.p_len;
|
||||||
T *cur = p_buf, *last = p_buf + p_len;
|
|
||||||
while (cur != last) (*cur++).~T();
|
|
||||||
}
|
|
||||||
p_len = v.p_len;
|
|
||||||
} else {
|
|
||||||
clear();
|
|
||||||
delete[] (uchar *)p_buf;
|
|
||||||
p_len = v.p_len;
|
|
||||||
p_cap = v.p_cap;
|
|
||||||
p_buf = (T *)new uchar[p_cap * sizeof(T)];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (octa::IsPod<T>()) {
|
if (octa::IsPod<T>()) {
|
||||||
memcpy(p_buf, v.p_buf, p_len * sizeof(T));
|
memcpy(p_buf, v.p_buf, p_len * sizeof(T));
|
||||||
} else {
|
} else {
|
||||||
|
@ -126,7 +114,6 @@ namespace octa {
|
||||||
new (cur++) T(*vbuf++);
|
new (cur++) T(*vbuf++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue