diff -u af/util/xp/old/ut_hash.cpp af/util/xp/ut_hash.cpp --- af/util/xp/old/ut_hash.cpp Sun Jul 13 06:08:24 2003 +++ af/util/xp/ut_hash.cpp Thu Oct 02 18:32:31 2003 @@ -184,8 +184,9 @@ */ const void* UT_StringPtrMap::pick(const char* k) const { - UT_String aKey(k); - return pick (aKey); + UT_Stringbuf sz(k); + UT_String aKey(&sz); + return pick (aKey); } const void* UT_StringPtrMap::pick(const UT_String & k) const diff -u af/util/xp/old/ut_string_class.cpp af/util/xp/ut_string_class.cpp --- af/util/xp/old/ut_string_class.cpp Thu Aug 28 01:50:00 2003 +++ af/util/xp/ut_string_class.cpp Thu Oct 02 23:06:24 2003 @@ -86,6 +86,11 @@ { } +UT_String::UT_String(UT_Stringbuf *psb) +: pimpl(psb) +{ +} + UT_String::UT_String(const UT_String& rhs) : pimpl(new UT_Stringbuf(*rhs.pimpl)) { @@ -93,7 +98,10 @@ UT_String::~UT_String() { - delete pimpl; + if (pimpl && (!pimpl->isExternal())) + { + delete pimpl; + } } diff -u af/util/xp/old/ut_string_class.h af/util/xp/ut_string_class.h --- af/util/xp/old/ut_string_class.h Tue Sep 02 15:10:54 2003 +++ af/util/xp/ut_string_class.h Thu Oct 02 22:11:46 2003 @@ -72,6 +72,7 @@ public: UT_String(); UT_String(const char* sz, size_t n = 0 /* 0 == zero-terminate */); + UT_String(UT_Stringbuf *psb); UT_String(const UT_String& rhs); ~UT_String(); diff -u af/util/xp/old/ut_stringbuf.cpp af/util/xp/ut_stringbuf.cpp --- af/util/xp/old/ut_stringbuf.cpp Fri Sep 05 14:18:39 2003 +++ af/util/xp/ut_stringbuf.cpp Thu Oct 02 23:03:09 2003 @@ -68,14 +68,16 @@ UT_Stringbuf::UT_Stringbuf() : m_psz(0), m_pEnd(0), - m_size(0) + m_size(0), + m_pszExternal(0) { } UT_Stringbuf::UT_Stringbuf(const UT_Stringbuf& rhs) : m_psz(new char_type[rhs.capacity()]), m_pEnd(m_psz + rhs.size()), - m_size(rhs.capacity()) + m_size(rhs.capacity()), + m_pszExternal(0) { copy(m_psz, rhs.m_psz, rhs.capacity()); } @@ -83,15 +85,28 @@ UT_Stringbuf::UT_Stringbuf(const char_type* sz, size_t n) : m_psz(new char_type[n+1]), m_pEnd(m_psz + n), - m_size(n+1) + m_size(n+1), + m_pszExternal(0) { copy(m_psz, sz, n); m_psz[n] = 0; } +UT_Stringbuf::UT_Stringbuf(const char_type* sz) +: m_psz((char *)sz), + m_pszExternal((char *)sz) +{ + UT_uint32 u = strlen((char *)sz); + m_size = u+1; + m_pEnd = (char *)sz + u; +} + UT_Stringbuf::~UT_Stringbuf() { - clear(); + if (NULL == m_pszExternal) + { + clear(); + } } @@ -106,6 +121,9 @@ void UT_Stringbuf::assign(const char_type* sz, size_t n) { + if (NULL != m_pszExternal) + return; + if (n) { if (n >= capacity()) @@ -122,7 +140,7 @@ void UT_Stringbuf::append(const char_type* sz, size_t n) { - if (!n) + if (!n || (NULL != m_pszExternal)) { return; } @@ -148,6 +166,7 @@ my_ut_swap(m_psz , rhs.m_psz ); my_ut_swap(m_pEnd, rhs.m_pEnd); my_ut_swap(m_size, rhs.m_size); + my_ut_swap(m_pszExternal, rhs.m_pszExternal); } void UT_Stringbuf::clear() @@ -173,6 +192,9 @@ void UT_Stringbuf::grow_common(size_t n, bool bCopy) { + if (NULL != m_pszExternal) + return; + ++n; // allow for zero termination if (n > capacity()) { diff -u af/util/xp/old/ut_stringbuf.h af/util/xp/ut_stringbuf.h --- af/util/xp/old/ut_stringbuf.h Tue Aug 05 15:53:03 2003 +++ af/util/xp/ut_stringbuf.h Thu Oct 02 23:02:44 2003 @@ -53,6 +53,7 @@ UT_Stringbuf(); UT_Stringbuf(const UT_Stringbuf& rhs); UT_Stringbuf(const char_type* sz, size_t n); + UT_Stringbuf(const char_type* sz); ~UT_Stringbuf(); void operator=(const UT_Stringbuf& rhs); @@ -69,6 +70,7 @@ size_t capacity() const { return m_size; } const char_type* data() const { return m_psz; } char_type* data() { return m_psz; } + bool isExternal() const { return (NULL != m_pszExternal); } private: void grow_nocopy(size_t n); @@ -80,6 +82,7 @@ char_type* m_psz; char_type* m_pEnd; size_t m_size; + char_type* m_pszExternal; }; ////////////////////////////////////////////////////////////////////////