From 28c6ff1cf5bdaa52159e94dd3fbe26b58aacb77e Mon Sep 17 00:00:00 2001 From: upstream svn Date: Fri, 23 Jan 2009 11:15:09 +0100 Subject: [PATCH] Upstream tarball 9389 --- .svn-revision | 2 +- src/RLE.cpp | 61 +++++++++++++++++++++-------------------------------------- src/RLE.h | 10 ++++++---- 3 files changed, 29 insertions(+), 44 deletions(-) diff --git a/.svn-revision b/.svn-revision index 0c9ca198..bb8a6f29 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -9388 +9389 diff --git a/src/RLE.cpp b/src/RLE.cpp index 53bd3e27..65672b4c 100644 --- a/src/RLE.cpp +++ b/src/RLE.cpp @@ -35,59 +35,42 @@ * We can't use implementation with "control char" since this encoder * will process binary data - not ascii (or unicode) strings */ -RLE_Data::RLE_Data(int len, bool use_diff) +void RLE_Data::setup(int len, bool use_diff, unsigned char * content) { m_len = len; m_use_diff = use_diff; - - m_buff = new unsigned char[m_len]; - memset(m_buff, 0, m_len); - // - // in worst case 2-byte sequence encoded as 3. So, data can grow at 1/3 - m_enc_buff = new unsigned char[m_len*4/3 + 1]; -} - -RLE_Data::RLE_Data() -{ - m_buff = 0; - m_enc_buff = 0; - m_len = 0; - m_use_diff = 0; -} -RLE_Data::RLE_Data(const RLE_Data &obj) -{ - m_len = obj.m_len; - m_use_diff = obj.m_use_diff; - - m_buff = new unsigned char[m_len]; - memcpy(m_buff, obj.m_buff, m_len); - - m_enc_buff = new unsigned char[m_len*4/3 + 1]; + if (m_len) { + m_buff = new unsigned char[m_len]; + if (content) { + memcpy(m_buff, content, m_len); + } else { + memset(m_buff, 0, m_len); + } + // + // in worst case 2-byte sequence encoded as 3. So, data can grow at 1/3 + m_enc_buff = new unsigned char[m_len*4/3 + 1]; + } else { + m_buff = m_enc_buff = 0; + } } RLE_Data &RLE_Data::operator=(const RLE_Data &obj) { - m_len = obj.m_len; - - m_use_diff = obj.m_use_diff; + if (this == &obj) + return *this; + + delete [] m_buff; + delete [] m_enc_buff; + setup(obj.m_len, obj.m_use_diff, obj.m_buff); - m_buff = new unsigned char[m_len]; - memcpy(m_buff, obj.m_buff, m_len); - - m_enc_buff = new unsigned char[m_len*4/3 + 1]; - return *this; } RLE_Data::~RLE_Data() { - if ( m_buff ) { - delete [] m_buff; - } - if ( m_enc_buff ) { - delete [] m_enc_buff; - } + delete [] m_buff; + delete [] m_enc_buff; } void RLE_Data::Realloc(int size) diff --git a/src/RLE.h b/src/RLE.h index 0ba03c6d..bd34c6f6 100644 --- a/src/RLE.h +++ b/src/RLE.h @@ -35,11 +35,11 @@ class RLE_Data { public: - RLE_Data(int len, bool use_diff); + RLE_Data(int len, bool use_diff) { setup(len, use_diff); } // those constructors are for stl containers - RLE_Data(); - RLE_Data(const RLE_Data &); + RLE_Data() { setup(0, 0); } + RLE_Data(const RLE_Data & obj) { setup(obj.m_len, obj.m_use_diff, obj.m_buff); } RLE_Data &operator=(const RLE_Data &); ~RLE_Data(); @@ -68,7 +68,9 @@ public: const unsigned char *Buffer() { return m_buff; } int Size() { return m_len; } -private: +private: + void setup(int len, bool use_diff, unsigned char * content = 0); + unsigned char *m_buff, *m_enc_buff; bool m_use_diff; int m_len, m_enc_len; -- 2.11.4.GIT