From 6c7c81559c61c7c1d06b141e6854fe5e00f0e02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Tue, 25 Jun 2019 12:05:22 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@811 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src_main/containers/pideque.h | 16 ++++++++++++---- src_main/containers/pivector.h | 26 +++++++++++++++----------- src_main/core/pibytearray.h | 6 +++--- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src_main/containers/pideque.h b/src_main/containers/pideque.h index 4b65cb9c..5e85360d 100755 --- a/src_main/containers/pideque.h +++ b/src_main/containers/pideque.h @@ -426,7 +426,7 @@ private: PIINTROSPECTION_CONTAINER_ALLOC(T, (as-pid_rsize)*sizeof(T)) if (pid_rsize > 0 && pid_data != 0) { memcpy((void*)(td + ns), (const void*)(pid_data + pid_start), pid_size * sizeof(T)); - deleteRaw(pid_data); + dealloc(); } pid_data = td; pid_rsize = as; @@ -448,10 +448,18 @@ private: template<> inline void PIDeque::deleteT(T * d, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz*sizeof(T));} \ template<> inline void PIDeque::elementNew(T * to, const T & from) {(*to) = from;} \ template<> inline void PIDeque::elementDelete(T & from) {;} \ - template<> inline PIDeque & PIDeque::_resizeRaw(size_t new_size) {if (new_size > pid_size) alloc(new_size, true); return *this;} \ + template<> inline PIDeque & PIDeque::_resizeRaw(size_t new_size) { \ + if (new_size > pid_size) { \ + PIINTROSPECTION_CONTAINER_USED(T, (new_size-pid_size)*sizeof(T)); \ + } \ + if (new_size < pid_size) { \ + PIINTROSPECTION_CONTAINER_UNUSED(T, (pid_size-new_size)*sizeof(T)); \ + } \ + alloc(new_size, true); \ + return *this; \ + } \ template<> inline PIDeque & PIDeque::clear() {PIINTROSPECTION_CONTAINER_UNUSED(T, pid_size*sizeof(T)); pid_size = 0; return *this;} \ - template<> inline PIDeque & PIDeque::assign(size_t new_size, const T & f) {\ - _resizeRaw(new_size); return fill(f);} + template<> inline PIDeque & PIDeque::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);} #else diff --git a/src_main/containers/pivector.h b/src_main/containers/pivector.h index a0900b63..60e3ce8b 100755 --- a/src_main/containers/pivector.h +++ b/src_main/containers/pivector.h @@ -324,16 +324,12 @@ private: elementDelete(d[i]); } } - inline void deleteRaw(T *& d) { - if ((uchar*)d != 0) free((uchar*)d); - d = 0; - } - inline void zeroRaw(T * d, size_t s) { - if ((uchar*)d != 0) memset(d, 0, s*sizeof(T)); - } inline void elementNew(T * to, const T & from) {new(to)T(from);} inline void elementDelete(T & from) {from.~T();} - inline void dealloc() {deleteRaw(piv_data);} + inline void dealloc() { + if ((uchar*)piv_data != 0) free((uchar*)piv_data); + piv_data = 0; + } inline void alloc(size_t new_size) { if (new_size <= piv_rsize) { piv_size = new_size; @@ -418,10 +414,18 @@ __PIVECTOR_SIMPLE_FUNCTIONS__(ldouble)*/ template<> inline void PIVector::deleteT(T * d, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz*sizeof(T));} \ template<> inline void PIVector::elementNew(T * to, const T & from) {(*to) = from;} \ template<> inline void PIVector::elementDelete(T & from) {;} \ - template<> inline PIVector & PIVector::_resizeRaw(size_t new_size) {alloc(new_size); return *this;} \ + template<> inline PIVector & PIVector::_resizeRaw(size_t new_size) { \ + if (new_size > piv_size) { \ + PIINTROSPECTION_CONTAINER_USED(T, (new_size-piv_size)*sizeof(T)); \ + } \ + if (new_size < piv_size) { \ + PIINTROSPECTION_CONTAINER_UNUSED(T, (piv_size-new_size)*sizeof(T)); \ + } \ + alloc(new_size); \ + return *this; \ + } \ template<> inline PIVector & PIVector::clear() {PIINTROSPECTION_CONTAINER_UNUSED(T, piv_size*sizeof(T)); piv_size = 0; return *this;} \ - template<> inline PIVector & PIVector::assign(size_t new_size, const T & f) {\ - _resizeRaw(new_size); return fill(f);} + template<> inline PIVector & PIVector::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);} #else diff --git a/src_main/core/pibytearray.h b/src_main/core/pibytearray.h index 285bd21f..d8047884 100755 --- a/src_main/core/pibytearray.h +++ b/src_main/core/pibytearray.h @@ -34,15 +34,15 @@ __PICONTAINERS_SIMPLE_TYPE__(PIChar) template<> \ inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \ template<> \ -inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); PIINTROSPECTION_CONTAINER_USED(T, sz*sizeof(T)); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \ +inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \ template<> \ inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \ template<> \ -inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); PIINTROSPECTION_CONTAINER_USED(T, sz*sizeof(T)); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \ +inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \ template<> \ inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D & v) {s << int(v.rows()) << int(v.cols()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \ template<> \ -inline PIByteArray & operator >>(PIByteArray & s, PIVector2D & v) {assert(s.size_s() >= 8); int r, c; s >> r >> c; v._resizeRaw(r, c); int sz = r*c; PIINTROSPECTION_CONTAINER_USED(T, sz*sizeof(T)); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIVector2D & v) {assert(s.size_s() >= 8); int r, c; s >> r >> c; v._resizeRaw(r, c); int sz = r*c; if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} class PIString;