summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tools/qstring.cpp133
1 files changed, 69 insertions, 64 deletions
diff --git a/src/tools/qstring.cpp b/src/tools/qstring.cpp
index 24339fcdb..808a0bea5 100644
--- a/src/tools/qstring.cpp
+++ b/src/tools/qstring.cpp
@@ -44,6 +44,11 @@
#undef QT_NO_CAST_ASCII
#endif
+// WARNING
+// When MAKE_TQSTRING_THREAD_SAFE is defined, overall TQt3 performance suffers badly!
+// TQString is thread unsafe in many other areas; perhaps this option is not even useful?
+// #define MAKE_TQSTRING_THREAD_SAFE 1
+
#include "ntqstring.h"
#include "ntqregexp.h"
#include "ntqdatastream.h"
@@ -87,9 +92,9 @@
#define ULLONG_MAX TQ_UINT64_C(18446744073709551615)
#endif
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
#include "ntqmutex.h"
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
extern TQMutex *tqt_sharedStringMutex;
@@ -1047,9 +1052,9 @@ TQStringData::TQStringData() : TQShared(),
maxl(0),
islatin1(FALSE),
security_unpaged(FALSE) {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
mutex = new TQMutex(FALSE);
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
ref();
}
@@ -1061,9 +1066,9 @@ TQStringData::TQStringData(TQChar *u, uint l, uint m) : TQShared(),
maxl(m),
islatin1(FALSE),
security_unpaged(FALSE) {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
mutex = new TQMutex(FALSE);
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
}
TQStringData::~TQStringData() {
@@ -1076,12 +1081,12 @@ TQStringData::~TQStringData() {
if ( ascii ) {
delete[] ascii;
}
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
if ( mutex ) {
delete mutex;
mutex = NULL;
}
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
}
void TQStringData::setDirty() {
@@ -1449,14 +1454,14 @@ QT_STATIC_CONST_IMPL TQChar TQChar::nbsp((ushort)0x00a0);
TQStringData* TQString::makeSharedNull()
{
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
if (tqt_sharedStringMutex) tqt_sharedStringMutex->lock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
if (TQString::shared_null) {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
if (tqt_sharedStringMutex) tqt_sharedStringMutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
return TQString::shared_null;
}
@@ -1466,9 +1471,9 @@ TQStringData* TQString::makeSharedNull()
that->d = TQString::shared_null;
#endif
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
if (tqt_sharedStringMutex) tqt_sharedStringMutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
return TQString::shared_null;
}
@@ -1509,13 +1514,13 @@ TQString::TQString( const TQString &s ) :
d(s.d)
{
if (d != shared_null) {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->lock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
d->ref();
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
}
}
@@ -1668,20 +1673,20 @@ TQString::~TQString()
return;
}
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->lock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
if ( d->deref() ) {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
d->deleteSelf();
d = NULL;
}
else {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
}
}
@@ -1703,22 +1708,22 @@ void TQString::real_detach()
void TQString::deref()
{
if ( d && (d != shared_null) ) {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->lock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
if ( d->deref() ) {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
if ( d != shared_null ) {
delete d;
}
d = 0;
}
else {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
}
}
}
@@ -1761,13 +1766,13 @@ void TQStringData::deleteSelf()
TQString &TQString::operator=( const TQString &s )
{
if (s.d != shared_null) {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
s.d->mutex->lock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
s.d->ref();
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
s.d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
}
deref();
d = s.d;
@@ -1875,9 +1880,9 @@ void TQString::truncate( uint newLen )
*/
void TQString::setLength( uint newLen )
{
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->lock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
if ( d->count != 1 || newLen > d->maxl ||
( newLen * 4 < d->maxl && d->maxl > 4 ) ) {
@@ -1888,24 +1893,24 @@ void TQString::setLength( uint newLen )
uint len = TQMIN( d->len, newLen );
memcpy( nd, d->unicode, sizeof(TQChar) * len );
bool unpaged = d->security_unpaged;
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
deref();
d = new TQStringData( nd, newLen, newMax );
setSecurityUnPaged(unpaged);
}
else {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
}
}
else {
d->len = newLen;
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
d->setDirty();
}
}
@@ -1991,21 +1996,21 @@ void TQString::squeeze()
*/
void TQString::grow( uint newLen )
{
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->lock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
if ( d->count != 1 || newLen > d->maxl ) {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
setLength( newLen );
}
else {
d->len = newLen;
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
d->setDirty();
}
}
@@ -6404,19 +6409,19 @@ TQString TQString::fromUcs2( const unsigned short *str )
*/
TQChar& TQString::ref(uint i) {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->lock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
if ( (d->count != 1) || (i >= d->len) ) {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
subat( i );
}
else {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
}
d->setDirty();
return d->unicode[i];
@@ -6504,9 +6509,9 @@ TQString& TQString::setUnicode( const TQChar *unicode, uint len )
}
}
else {
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->lock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_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 @@ TQString& TQString::setUnicode( const TQChar *unicode, uint len )
if ( unicode ) {
memcpy( nd, unicode, sizeof(TQChar)*len );
}
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
deref();
d = new TQStringData( nd, len, newMax );
}
else {
d->len = len;
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
d->setDirty();
if ( unicode ) {
memcpy( d->unicode, unicode, sizeof(TQChar)*len );
@@ -7235,9 +7240,9 @@ TQConstString::TQConstString( const TQChar* unicode, uint length ) :
*/
TQConstString::~TQConstString()
{
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->lock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
if ( d->count > 1 ) {
TQChar* cp = QT_ALLOC_QCHAR_VEC( d->len );
@@ -7249,9 +7254,9 @@ TQConstString::~TQConstString()
}
// The original d->unicode is now unlinked.
-#ifdef QT_THREAD_SUPPORT
+#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
d->mutex->unlock();
-#endif // QT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
}
/*!