X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a0b7b493504f8ef023962f0282eeef3bca5600f9..d6a658ff0cd928953efdaf1ea56ff04b9cf281c1:/src/common/stringimpl.cpp diff --git a/src/common/stringimpl.cpp b/src/common/stringimpl.cpp index d626556df9..429f3843bd 100644 --- a/src/common/stringimpl.cpp +++ b/src/common/stringimpl.cpp @@ -77,9 +77,9 @@ const size_t wxStringImpl::npos = (size_t) -1; // FIXME-UTF8: get rid of this, have only one wxEmptyString #if wxUSE_UNICODE_UTF8 -extern const wxStringCharType WXDLLIMPEXP_BASE *wxEmptyStringImpl = ""; +const wxStringCharType WXDLLIMPEXP_BASE *wxEmptyStringImpl = ""; #endif -extern const wxChar WXDLLIMPEXP_BASE *wxEmptyString = _T(""); +const wxChar WXDLLIMPEXP_BASE *wxEmptyString = wxT(""); #else @@ -95,10 +95,10 @@ static const struct // empty C style string: points to 'string data' byte of g_strEmpty #if wxUSE_UNICODE_UTF8 // FIXME-UTF8: get rid of this, have only one wxEmptyString -extern const wxStringCharType WXDLLIMPEXP_BASE *wxEmptyStringImpl = &g_strEmpty.dummy; -extern const wxChar WXDLLIMPEXP_BASE *wxEmptyString = _T(""); +const wxStringCharType WXDLLIMPEXP_BASE *wxEmptyStringImpl = &g_strEmpty.dummy; +const wxChar WXDLLIMPEXP_BASE *wxEmptyString = wxT(""); #else -extern const wxStringCharType WXDLLIMPEXP_BASE *wxEmptyString = &g_strEmpty.dummy; +const wxStringCharType WXDLLIMPEXP_BASE *wxEmptyString = &g_strEmpty.dummy; #endif #endif @@ -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"), @@ -159,7 +166,7 @@ void wxStringImpl::InitWith(const wxStringCharType *psz, // if the length is not given, assume the string to be NUL terminated if ( nLength == npos ) { - wxASSERT_MSG( nPos <= wxStrlen(psz), _T("index out of bounds") ); + wxASSERT_MSG( nPos <= wxStrlen(psz), wxT("index out of bounds") ); nLength = wxStrlen(psz + nPos); } @@ -169,7 +176,7 @@ void wxStringImpl::InitWith(const wxStringCharType *psz, if ( nLength > 0 ) { // trailing '\0' is written in AllocBuffer() if ( !AllocBuffer(nLength) ) { - wxFAIL_MSG( _T("out of memory in wxStringImpl::InitWith") ); + wxFAIL_MSG( wxT("out of memory in wxStringImpl::InitWith") ); return; } wxStringMemcpy(m_pchData, psz + nPos, nLength); @@ -184,7 +191,7 @@ wxStringImpl::wxStringImpl(const_iterator first, const_iterator last) } else { - wxFAIL_MSG( _T("first must be before last") ); + wxFAIL_MSG( wxT("first must be before last") ); Init(); } } @@ -304,7 +311,7 @@ wxStringImpl& wxStringImpl::append(size_t n, wxStringCharType ch) size_type len = length(); if ( !Alloc(len + n) || !CopyBeforeWrite() ) { - wxFAIL_MSG( _T("out of memory in wxStringImpl::append") ); + wxFAIL_MSG( wxT("out of memory in wxStringImpl::append") ); return *this; } GetStringData()->nDataLength = len + n; @@ -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 *) @@ -427,7 +436,7 @@ wxStringImpl& wxStringImpl::insert(size_t nPos, if ( n == 0 ) return *this; if ( !Alloc(length() + n) || !CopyBeforeWrite() ) { - wxFAIL_MSG( _T("out of memory in wxStringImpl::insert") ); + wxFAIL_MSG( wxT("out of memory in wxStringImpl::insert") ); return *this; } @@ -578,7 +587,7 @@ wxStringImpl& wxStringImpl::replace(size_t nStart, size_t nLen, const size_t lenOld = length(); wxASSERT_MSG( nStart <= lenOld, - _T("index out of bounds in wxStringImpl::replace") ); + wxT("index out of bounds in wxStringImpl::replace") ); size_t nEnd = nStart + nLen; if ( nLen > lenOld - nStart ) { @@ -646,7 +655,7 @@ wxStringImpl& wxStringImpl::operator=(wxStringCharType ch) { wxStringCharType c(ch); if ( !AssignCopy(1, &c) ) { - wxFAIL_MSG( _T("out of memory in wxStringImpl::operator=(wxStringCharType)") ); + wxFAIL_MSG( wxT("out of memory in wxStringImpl::operator=(wxStringCharType)") ); } return *this; } @@ -655,7 +664,7 @@ wxStringImpl& wxStringImpl::operator=(wxStringCharType ch) wxStringImpl& wxStringImpl::operator=(const wxStringCharType *psz) { if ( !AssignCopy(wxStrlen(psz), psz) ) { - wxFAIL_MSG( _T("out of memory in wxStringImpl::operator=(const wxStringCharType *)") ); + wxFAIL_MSG( wxT("out of memory in wxStringImpl::operator=(const wxStringCharType *)") ); } return *this; } @@ -775,10 +784,10 @@ void wxStringImpl::DoUngetWriteBuf(size_t nLen) { wxStringData * const pData = GetStringData(); - wxASSERT_MSG( nLen < pData->nAllocLength, _T("buffer overrun") ); + wxASSERT_MSG( nLen < pData->nAllocLength, wxT("buffer overrun") ); // the strings we store are always NUL-terminated - pData->data()[nLen] = _T('\0'); + pData->data()[nLen] = wxT('\0'); pData->nDataLength = nLen; pData->Validate(true); }