diff --git a/ChangeLog b/ChangeLog index 2bd8aec8..7c7ca8a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2007-12-09 Tatsuhiro Tsujikawa + Removed unnecessary string copy. Updated doc and corrected indentation. + * src/Base64.cc + * Release 0.12.0 2007-12-09 Tatsuhiro Tsujikawa diff --git a/src/Base64.cc b/src/Base64.cc index 7cd87025..6c5ee218 100644 --- a/src/Base64.cc +++ b/src/Base64.cc @@ -65,7 +65,7 @@ static const int INDEX_TABLE[] = { }; void Base64::encode(unsigned char*& result, size_t& rlength, - const unsigned char* src, size_t slength) + const unsigned char* src, size_t slength) { if(slength == 0) { rlength = 0; @@ -105,9 +105,9 @@ void Base64::encode(unsigned char*& result, size_t& rlength, } void Base64::removeNonBase64Chars(unsigned char*& nsrc, - size_t& nlength, - const unsigned char* src, - size_t slength) + size_t& nlength, + const unsigned char* src, + size_t slength) { unsigned char* temp = new unsigned char[slength]; const unsigned char* end = src+slength; @@ -117,15 +117,12 @@ void Base64::removeNonBase64Chars(unsigned char*& nsrc, *(temp+n++) = *s; } } - unsigned char* ret = new unsigned char[n]; - memcpy(ret, temp, n); - delete [] temp; nlength = n; - nsrc = ret; + nsrc = temp; } void Base64::decode(unsigned char*& result, size_t& rlength, - const unsigned char* src, size_t slength) + const unsigned char* src, size_t slength) { if(slength == 0) { rlength = 0; diff --git a/src/Base64.h b/src/Base64.h index 59914b94..3c64cade 100644 --- a/src/Base64.h +++ b/src/Base64.h @@ -41,6 +41,11 @@ using namespace std; class Base64 { private: + /** + * Removes non base64 chars(including '=') from src, and results are + * stored in nsrc and its length is stored in nlength. + * Caller must delete nsrc. + */ static void removeNonBase64Chars(unsigned char*& nsrc, size_t& nlength, const unsigned char* src, size_t slength);