From: Mikko Rasa Date: Sun, 2 Sep 2012 14:30:54 +0000 (+0300) Subject: Memory allocation changes X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=77656543441a130276e0a37ba119270edd9156ff Memory allocation changes Use std::copy instead of memcpy Call operator= from copy constructor Allocate memory only when needed, not one byte before --- diff --git a/source/vertexformat.cpp b/source/vertexformat.cpp index 65b276ba..0a26d942 100644 --- a/source/vertexformat.cpp +++ b/source/vertexformat.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -24,11 +24,7 @@ VertexFormat::VertexFormat(VertexComponent c): VertexFormat::VertexFormat(const VertexFormat &f): data(0) { - if(f.data) - { - data = new unsigned char[(f.data[0]&~7)+8]; - memcpy(data, f.data, f.data[0]+1); - } + *this = f; } VertexFormat &VertexFormat::operator=(const VertexFormat &f) @@ -37,7 +33,7 @@ VertexFormat &VertexFormat::operator=(const VertexFormat &f) if(f.data) { data = new unsigned char[(f.data[0]&~7)+8]; - memcpy(data, f.data, f.data[0]+1); + copy(f.data, f.data+f.data[0]+1, data); } else data = 0; @@ -56,10 +52,10 @@ VertexFormat VertexFormat::operator,(VertexComponent c) const if(r.data) { const unsigned char n = ++r.data[0]; - if((n&7)==7) + if((n&7)==0) { - unsigned char *newdt = new unsigned char[n+9]; - memcpy(newdt, r.data, n); + unsigned char *newdt = new unsigned char[n+8]; + copy(r.data, r.data+n, newdt); delete r.data; r.data = newdt; }