|
|
|
@ -44,6 +44,11 @@
|
|
|
|
|
#undef QT_NO_CAST_ASCII
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// WARNING
|
|
|
|
|
// When MAKE_QSTRING_THREAD_SAFE is defined, overall Qt3 performance suffers badly!
|
|
|
|
|
// QString is thread unsafe in many other areas; perhaps this option is not even useful?
|
|
|
|
|
// #define MAKE_QSTRING_THREAD_SAFE 1
|
|
|
|
|
|
|
|
|
|
#include "qstring.h"
|
|
|
|
|
#include "qregexp.h"
|
|
|
|
|
#include "qdatastream.h"
|
|
|
|
@ -87,9 +92,9 @@
|
|
|
|
|
#define ULLONG_MAX Q_UINT64_C(18446744073709551615)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
#include "qmutex.h"
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
|
|
|
|
|
extern QMutex *qt_sharedStringMutex;
|
|
|
|
|
|
|
|
|
@ -1047,9 +1052,9 @@ QStringData::QStringData() : QShared(),
|
|
|
|
|
maxl(0),
|
|
|
|
|
islatin1(FALSE),
|
|
|
|
|
security_unpaged(FALSE) {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
mutex = new QMutex(FALSE);
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
ref();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1061,9 +1066,9 @@ QStringData::QStringData(QChar *u, uint l, uint m) : QShared(),
|
|
|
|
|
maxl(m),
|
|
|
|
|
islatin1(FALSE),
|
|
|
|
|
security_unpaged(FALSE) {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
mutex = new QMutex(FALSE);
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringData::~QStringData() {
|
|
|
|
@ -1076,12 +1081,12 @@ QStringData::~QStringData() {
|
|
|
|
|
if ( ascii ) {
|
|
|
|
|
delete[] ascii;
|
|
|
|
|
}
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
if ( mutex ) {
|
|
|
|
|
delete mutex;
|
|
|
|
|
mutex = NULL;
|
|
|
|
|
}
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QStringData::setDirty() {
|
|
|
|
@ -1449,14 +1454,14 @@ QT_STATIC_CONST_IMPL QChar QChar::nbsp((ushort)0x00a0);
|
|
|
|
|
|
|
|
|
|
QStringData* QString::makeSharedNull()
|
|
|
|
|
{
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
if (qt_sharedStringMutex) qt_sharedStringMutex->lock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
|
|
|
|
|
if (QString::shared_null) {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
if (qt_sharedStringMutex) qt_sharedStringMutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
return QString::shared_null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1466,9 +1471,9 @@ QStringData* QString::makeSharedNull()
|
|
|
|
|
that->d = QString::shared_null;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
if (qt_sharedStringMutex) qt_sharedStringMutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
return QString::shared_null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1509,13 +1514,13 @@ QString::QString( const QString &s ) :
|
|
|
|
|
d(s.d)
|
|
|
|
|
{
|
|
|
|
|
if (d != shared_null) {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->lock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
d->ref();
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1668,20 +1673,20 @@ QString::~QString()
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->lock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
if ( d->deref() ) {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
d->deleteSelf();
|
|
|
|
|
d = NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1703,22 +1708,22 @@ void QString::real_detach()
|
|
|
|
|
void QString::deref()
|
|
|
|
|
{
|
|
|
|
|
if ( d && (d != shared_null) ) {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->lock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
if ( d->deref() ) {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
if ( d != shared_null ) {
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
d = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1761,13 +1766,13 @@ void QStringData::deleteSelf()
|
|
|
|
|
QString &QString::operator=( const QString &s )
|
|
|
|
|
{
|
|
|
|
|
if (s.d != shared_null) {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
s.d->mutex->lock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
s.d->ref();
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
s.d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
}
|
|
|
|
|
deref();
|
|
|
|
|
d = s.d;
|
|
|
|
@ -1875,9 +1880,9 @@ void QString::truncate( uint newLen )
|
|
|
|
|
*/
|
|
|
|
|
void QString::setLength( uint newLen )
|
|
|
|
|
{
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->lock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
|
|
|
|
|
if ( d->count != 1 || newLen > d->maxl ||
|
|
|
|
|
( newLen * 4 < d->maxl && d->maxl > 4 ) ) {
|
|
|
|
@ -1888,24 +1893,24 @@ void QString::setLength( uint newLen )
|
|
|
|
|
uint len = QMIN( d->len, newLen );
|
|
|
|
|
memcpy( nd, d->unicode, sizeof(QChar) * len );
|
|
|
|
|
bool unpaged = d->security_unpaged;
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
deref();
|
|
|
|
|
d = new QStringData( nd, newLen, newMax );
|
|
|
|
|
setSecurityUnPaged(unpaged);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
d->len = newLen;
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
d->setDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1991,21 +1996,21 @@ void QString::squeeze()
|
|
|
|
|
*/
|
|
|
|
|
void QString::grow( uint newLen )
|
|
|
|
|
{
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->lock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
|
|
|
|
|
if ( d->count != 1 || newLen > d->maxl ) {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
setLength( newLen );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
d->len = newLen;
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
d->setDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -6404,19 +6409,19 @@ QString QString::fromUcs2( const unsigned short *str )
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
QChar& QString::ref(uint i) {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->lock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
if ( (d->count != 1) || (i >= d->len) ) {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
subat( i );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
}
|
|
|
|
|
d->setDirty();
|
|
|
|
|
return d->unicode[i];
|
|
|
|
@ -6504,9 +6509,9 @@ QString& QString::setUnicode( const QChar *unicode, uint len )
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->lock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
if ( d->count != 1 || len > d->maxl || ( len * 4 < d->maxl && d->maxl > 4 ) ) {
|
|
|
|
|
// detach, grown or shrink
|
|
|
|
|
uint newMax = computeNewMax( len );
|
|
|
|
@ -6514,17 +6519,17 @@ QString& QString::setUnicode( const QChar *unicode, uint len )
|
|
|
|
|
if ( unicode ) {
|
|
|
|
|
memcpy( nd, unicode, sizeof(QChar)*len );
|
|
|
|
|
}
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
deref();
|
|
|
|
|
d = new QStringData( nd, len, newMax );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
d->len = len;
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
d->setDirty();
|
|
|
|
|
if ( unicode ) {
|
|
|
|
|
memcpy( d->unicode, unicode, sizeof(QChar)*len );
|
|
|
|
@ -7235,9 +7240,9 @@ QConstString::QConstString( const QChar* unicode, uint length ) :
|
|
|
|
|
*/
|
|
|
|
|
QConstString::~QConstString()
|
|
|
|
|
{
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->lock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
|
|
|
|
|
if ( d->count > 1 ) {
|
|
|
|
|
QChar* cp = QT_ALLOC_QCHAR_VEC( d->len );
|
|
|
|
@ -7249,9 +7254,9 @@ QConstString::~QConstString()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The original d->unicode is now unlinked.
|
|
|
|
|
#ifdef QT_THREAD_SUPPORT
|
|
|
|
|
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
|
|
|
|
|
d->mutex->unlock();
|
|
|
|
|
#endif // QT_THREAD_SUPPORT
|
|
|
|
|
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|