Avoid unnecessary copying in copyIn

Only re-use the existing reference if
it is large enough to hold all the new data.
If it isn't then throw it away to avoid
copying its current contents during
the resize().
This commit is contained in:
Michael Davidsaver
2013-05-23 18:19:26 -04:00
parent 54ee8bf7a0
commit 9e865bc37d

View File

@@ -1319,6 +1319,10 @@ public:
{
svector data;
this->swap(data);
// Will have to re-alloc anyway? If so avoid copying
// data which will only be over-written
if(data.capacity()<len)
data.clear();
data.resize(len);
castUnsafeV(len, typeCode, (void*)data.data(), id, ptr);
this->swap(data);