X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fb25206791c8324c946fb724f21c913b5f3b295e..a2fd8a45eca03f90371a1c41b2f7450df088b07c:/src/common/stringimpl.cpp diff --git a/src/common/stringimpl.cpp b/src/common/stringimpl.cpp index e182044be1..d0a7165ce7 100644 --- a/src/common/stringimpl.cpp +++ b/src/common/stringimpl.cpp @@ -111,19 +111,26 @@ extern const wxStringCharType WXDLLIMPEXP_BASE *wxEmptyString = &g_strEmpty.dumm // ---------------------------------------------------------------------------- // this small class is used to gather statistics for performance tuning + +// uncomment this to enable gathering of some statistics about wxString +// efficiency //#define WXSTRING_STATISTICS + #ifdef WXSTRING_STATISTICS class Averager { public: Averager(const wxStringCharType *sz) { m_sz = sz; m_nTotal = m_nCount = 0; } ~Averager() - { wxPrintf("wxString: average %s = %f\n", m_sz, ((float)m_nTotal)/m_nCount); } + { + wxPrintf("wxString %s: total = %lu, average = %f\n", + m_sz, m_nTotal, ((float)m_nTotal)/m_nCount); + } void Add(size_t n) { m_nTotal += n; m_nCount++; } private: - size_t m_nCount, m_nTotal; + unsigned long m_nCount, m_nTotal; const wxStringCharType *m_sz; } g_averageLength("allocation size"), g_averageSummandLength("summand length"), @@ -207,8 +214,8 @@ bool wxStringImpl::AllocBuffer(size_t nLen) wxASSERT( nLen > 0 ); // make sure that we don't overflow - wxASSERT( nLen < (INT_MAX / sizeof(wxStringCharType)) - - (sizeof(wxStringData) + EXTRA_ALLOC + 1) ); + wxCHECK( nLen < (INT_MAX / sizeof(wxStringCharType)) - + (sizeof(wxStringData) + EXTRA_ALLOC + 1), false ); STATISTICS_ADD(Length, nLen); @@ -335,6 +342,8 @@ bool wxStringImpl::Alloc(size_t nLen) wxStringData *pData = GetStringData(); if ( pData->nAllocLength <= nLen ) { if ( pData->IsEmpty() ) { + STATISTICS_ADD(Length, nLen); + nLen += EXTRA_ALLOC; pData = (wxStringData *)