From 49301e2eba98773f99c7af1155e90b31a3e53e0a Mon Sep 17 00:00:00 2001 From: jez <> Date: Fri, 19 Jan 2007 15:53:46 +0000 Subject: [PATCH] stop allocating a buffer everytime we do a conversion --- include/Utils/convertstream.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/include/Utils/convertstream.h b/include/Utils/convertstream.h index edd09e80..b7b993bc 100644 --- a/include/Utils/convertstream.h +++ b/include/Utils/convertstream.h @@ -138,8 +138,6 @@ public: // we must do code conversion stringT converted; - size_t toBufLen = str.length() + 4; // 4 is arbitrary bit of bonus space - charT* to = new charT[toBufLen]; // 4 is arbitrary const fromCharT* from_next = str.data(); typename std::codecvt_base::result r; typename traitsT::state_type state; @@ -148,19 +146,17 @@ public: { charT* to_next; r = cvt.in(state, from_next, str.data() + str.length(), from_next, - to, to + toBufLen, to_next); + to_, to_ + toSize_, to_next); if(r == std::codecvt_base::noconv) { converted.append(no_conversion(str)); break; } - converted.append(to, (to_next - to)); + converted.append(to_, (to_next - to_)); } while(r == std::codecvt_base::partial); - delete[] to; // naughty! ignore (r == std::codecvt_base::error) - convertstreambuf_initT::buf()->str(converted); } // str @@ -180,6 +176,9 @@ private: return dest; } // no_conversion + + static const int toSize_ = 4096; + charT to_[toSize_]; }; // basic_iconvertstream template converting_istringstream;