projects
/
wxWidgets.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix warnings about wxOSX_USE_CARBON being undefined when using g++.
[wxWidgets.git]
/
src
/
common
/
stringimpl.cpp
diff --git
a/src/common/stringimpl.cpp
b/src/common/stringimpl.cpp
index 95d686330143ace1c9ddc08b4d8c4c16448194fe..ed9a83e476e14e4c406cabe32eca5aba2efa94c9 100644
(file)
--- a/
src/common/stringimpl.cpp
+++ b/
src/common/stringimpl.cpp
@@
-42,10
+42,6
@@
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
-#ifdef __SALFORDC__
- #include <clib.h>
-#endif
-
// allocating extra space for each string consumes more memory but speeds up
// the concatenation operations (nLen is the current string's length)
// NB: EXTRA_ALLOC must be >= 0!
// allocating extra space for each string consumes more memory but speeds up
// the concatenation operations (nLen is the current string's length)
// NB: EXTRA_ALLOC must be >= 0!
@@
-81,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
// 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
#endif
-
extern const wxChar WXDLLIMPEXP_BASE *wxEmptyString = _
T("");
+
const wxChar WXDLLIMPEXP_BASE *wxEmptyString = wx
T("");
#else
#else
@@
-99,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
// 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 = wx
T("");
#else
#else
-
extern
const wxStringCharType WXDLLIMPEXP_BASE *wxEmptyString = &g_strEmpty.dummy;
+const wxStringCharType WXDLLIMPEXP_BASE *wxEmptyString = &g_strEmpty.dummy;
#endif
#endif
#endif
#endif
@@
-115,19
+111,26
@@
extern const wxStringCharType WXDLLIMPEXP_BASE *wxEmptyString = &g_strEmpty.dumm
// ----------------------------------------------------------------------------
// this small class is used to gather statistics for performance tuning
// ----------------------------------------------------------------------------
// 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
//#define WXSTRING_STATISTICS
+
#ifdef WXSTRING_STATISTICS
class Averager
{
public:
Averager(const wxStringCharType *sz) { m_sz = sz; m_nTotal = m_nCount = 0; }
~Averager()
#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:
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"),
const wxStringCharType *m_sz;
} g_averageLength("allocation size"),
g_averageSummandLength("summand length"),
@@
-163,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 ) {
// 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),
wx
T("index out of bounds") );
nLength = wxStrlen(psz + nPos);
}
nLength = wxStrlen(psz + nPos);
}
@@
-173,7
+176,7
@@
void wxStringImpl::InitWith(const wxStringCharType *psz,
if ( nLength > 0 ) {
// trailing '\0' is written in AllocBuffer()
if ( !AllocBuffer(nLength) ) {
if ( nLength > 0 ) {
// trailing '\0' is written in AllocBuffer()
if ( !AllocBuffer(nLength) ) {
- wxFAIL_MSG(
_
T("out of memory in wxStringImpl::InitWith") );
+ wxFAIL_MSG(
wx
T("out of memory in wxStringImpl::InitWith") );
return;
}
wxStringMemcpy(m_pchData, psz + nPos, nLength);
return;
}
wxStringMemcpy(m_pchData, psz + nPos, nLength);
@@
-184,11
+187,11
@@
wxStringImpl::wxStringImpl(const_iterator first, const_iterator last)
{
if ( last >= first )
{
{
if ( last >= first )
{
- InitWith(first, 0, last - first);
+ InitWith(first
.GetPtr()
, 0, last - first);
}
else
{
}
else
{
- wxFAIL_MSG(
_
T("first must be before last") );
+ wxFAIL_MSG(
wx
T("first must be before last") );
Init();
}
}
Init();
}
}
@@
-211,8
+214,8
@@
bool wxStringImpl::AllocBuffer(size_t nLen)
wxASSERT( nLen > 0 );
// make sure that we don't overflow
wxASSERT( nLen > 0 );
// make sure that we don't overflow
- wx
ASSERT
( nLen < (INT_MAX / sizeof(wxStringCharType)) -
-
(sizeof(wxStringData) + EXTRA_ALLOC + 1)
);
+ wx
CHECK
( nLen < (INT_MAX / sizeof(wxStringCharType)) -
+
(sizeof(wxStringData) + EXTRA_ALLOC + 1), false
);
STATISTICS_ADD(Length, nLen);
STATISTICS_ADD(Length, nLen);
@@
-308,7
+311,7
@@
wxStringImpl& wxStringImpl::append(size_t n, wxStringCharType ch)
size_type len = length();
if ( !Alloc(len + n) || !CopyBeforeWrite() ) {
size_type len = length();
if ( !Alloc(len + n) || !CopyBeforeWrite() ) {
- wxFAIL_MSG(
_
T("out of memory in wxStringImpl::append") );
+ wxFAIL_MSG(
wx
T("out of memory in wxStringImpl::append") );
return *this;
}
GetStringData()->nDataLength = len + n;
return *this;
}
GetStringData()->nDataLength = len + n;
@@
-339,6
+342,8
@@
bool wxStringImpl::Alloc(size_t nLen)
wxStringData *pData = GetStringData();
if ( pData->nAllocLength <= nLen ) {
if ( pData->IsEmpty() ) {
wxStringData *pData = GetStringData();
if ( pData->nAllocLength <= nLen ) {
if ( pData->IsEmpty() ) {
+ STATISTICS_ADD(Length, nLen);
+
nLen += EXTRA_ALLOC;
pData = (wxStringData *)
nLen += EXTRA_ALLOC;
pData = (wxStringData *)
@@
-390,14
+395,14
@@
bool wxStringImpl::Alloc(size_t nLen)
wxStringImpl::iterator wxStringImpl::begin()
{
wxStringImpl::iterator wxStringImpl::begin()
{
- if (
length() > 0
)
+ if (
!empty()
)
CopyBeforeWrite();
return m_pchData;
}
wxStringImpl::iterator wxStringImpl::end()
{
CopyBeforeWrite();
return m_pchData;
}
wxStringImpl::iterator wxStringImpl::end()
{
- if (
length() > 0
)
+ if (
!empty()
)
CopyBeforeWrite();
return m_pchData + length();
}
CopyBeforeWrite();
return m_pchData + length();
}
@@
-431,7
+436,7
@@
wxStringImpl& wxStringImpl::insert(size_t nPos,
if ( n == 0 ) return *this;
if ( !Alloc(length() + n) || !CopyBeforeWrite() ) {
if ( n == 0 ) return *this;
if ( !Alloc(length() + n) || !CopyBeforeWrite() ) {
- wxFAIL_MSG(
_
T("out of memory in wxStringImpl::insert") );
+ wxFAIL_MSG(
wx
T("out of memory in wxStringImpl::insert") );
return *this;
}
return *this;
}
@@
-523,7
+528,7
@@
size_t wxStringImpl::rfind(const wxStringImpl& str, size_t nStart) const
if ( length() >= str.length() )
{
// avoids a corner case later
if ( length() >= str.length() )
{
// avoids a corner case later
- if (
length() == 0 && str.length() == 0
)
+ if (
empty() && str.empty()
)
return 0;
// "top" is the point where search starts from
return 0;
// "top" is the point where search starts from
@@
-582,9
+587,9
@@
wxStringImpl& wxStringImpl::replace(size_t nStart, size_t nLen,
const size_t lenOld = length();
wxASSERT_MSG( nStart <= lenOld,
const size_t lenOld = length();
wxASSERT_MSG( nStart <= lenOld,
-
_
T("index out of bounds in wxStringImpl::replace") );
+
wx
T("index out of bounds in wxStringImpl::replace") );
size_t nEnd = nStart + nLen;
size_t nEnd = nStart + nLen;
- if ( n
End > lenOld
)
+ if ( n
Len > lenOld - nStart
)
{
// nLen may be out of range, as it can be npos, just clump it down
nLen = lenOld - nStart;
{
// nLen may be out of range, as it can be npos, just clump it down
nLen = lenOld - nStart;
@@
-650,7
+655,7
@@
wxStringImpl& wxStringImpl::operator=(wxStringCharType ch)
{
wxStringCharType c(ch);
if ( !AssignCopy(1, &c) ) {
{
wxStringCharType c(ch);
if ( !AssignCopy(1, &c) ) {
- wxFAIL_MSG(
_
T("out of memory in wxStringImpl::operator=(wxStringCharType)") );
+ wxFAIL_MSG(
wx
T("out of memory in wxStringImpl::operator=(wxStringCharType)") );
}
return *this;
}
}
return *this;
}
@@
-659,7
+664,7
@@
wxStringImpl& wxStringImpl::operator=(wxStringCharType ch)
wxStringImpl& wxStringImpl::operator=(const wxStringCharType *psz)
{
if ( !AssignCopy(wxStrlen(psz), psz) ) {
wxStringImpl& wxStringImpl::operator=(const wxStringCharType *psz)
{
if ( !AssignCopy(wxStrlen(psz), psz) ) {
- wxFAIL_MSG(
_
T("out of memory in wxStringImpl::operator=(const wxStringCharType *)") );
+ wxFAIL_MSG(
wx
T("out of memory in wxStringImpl::operator=(const wxStringCharType *)") );
}
return *this;
}
}
return *this;
}
@@
-779,10
+784,10
@@
void wxStringImpl::DoUngetWriteBuf(size_t nLen)
{
wxStringData * const pData = GetStringData();
{
wxStringData * const pData = GetStringData();
- wxASSERT_MSG( nLen < pData->nAllocLength,
_
T("buffer overrun") );
+ wxASSERT_MSG( nLen < pData->nAllocLength,
wx
T("buffer overrun") );
// the strings we store are always NUL-terminated
// the strings we store are always NUL-terminated
- pData->data()[nLen] =
_
T('\0');
+ pData->data()[nLen] =
wx
T('\0');
pData->nDataLength = nLen;
pData->Validate(true);
}
pData->nDataLength = nLen;
pData->Validate(true);
}