[prev in list] [next in list] [prev in thread] [next in thread]
List: kmail-devel
Subject: Re: Displaying large message takes loooong
From: Don Sanders <sanders () kde ! org>
Date: 2002-10-16 17:36:54
[Download RAW message or body]
On Tuesday 15 October 2002 19:07, Marc Mutz wrote:
> On Tuesday 15 October 2002 08:53, Don Sanders wrote:
> <snip>
>
> > Martin sent me the mail and I can reproduce the problem. There's
> > something very wrong going on here, so maybe I can get this
> > optimization into 3.1 as a bug fix.
>
> <snip>
>
> This would be cool!
The problem is replace does a while( (index = find( before, index ) ) != -1 )
and find calls length and length does a strlen on data().
So for Martin's attachment strlen gets called on an 800k string 7k times.
I'm thinking of a fix something like this.
Don.
["qcstring.diff" (text/x-diff)]
Index: tools/qcstring.h
===================================================================
RCS file: /home/kde/qt-copy/src/tools/qcstring.h,v
retrieving revision 1.45
diff -d -u -b -p -r1.45 qcstring.h
--- tools/qcstring.h 2002/09/06 12:32:03 1.45
+++ tools/qcstring.h 2002/10/16 17:14:48
@@ -232,6 +232,8 @@ public:
operator const char *() const;
QCString &operator+=( const char *str );
QCString &operator+=( char c );
+private:
+ int find( const char *str, int index, bool cs, uint l ) const;
};
Index: tools/qcstring.cpp
===================================================================
RCS file: /home/kde/qt-copy/src/tools/qcstring.cpp,v
retrieving revision 1.45
diff -d -u -b -p -r1.45 qcstring.cpp
--- tools/qcstring.cpp 2002/09/06 12:32:03 1.45
+++ tools/qcstring.cpp 2002/10/16 17:14:51
@@ -931,13 +931,17 @@ int QCString::find( char c, int index, b
int QCString::find( const char *str, int index, bool cs ) const
{
+ find( str, index, cs, length() );
+}
+
+int QCString::find( const char *str, int index, bool cs, uint l ) const
+{
if ( (uint)index >= size() )
return -1;
if ( !str )
return -1;
if ( !*str )
return index;
- const uint l = length();
const uint sl = qstrlen( str );
if ( sl + index > l )
return -1;
@@ -1168,7 +1172,6 @@ int QCString::contains( const char *str,
\sa right(), mid()
*/
-
QCString QCString::left( uint len ) const
{
if ( isEmpty() ) {
@@ -1626,6 +1629,7 @@ QCString &QCString::replace( char c, con
// s == "English is English"
\endcode
*/
+
QCString &QCString::replace( const char *before, const char *after )
{
if ( before == after || isNull() )
@@ -1641,7 +1645,7 @@ QCString &QCString::replace( const char
if ( bl == al ) {
if ( bl ) {
- while( (index = find( before, index ) ) != -1 ) {
+ while( (index = find( before, index, TRUE, len ) ) != -1 ) {
memcpy( d+index, after, al );
index += bl;
}
@@ -1650,7 +1654,7 @@ QCString &QCString::replace( const char
uint to = 0;
uint movestart = 0;
uint num = 0;
- while( (index = find( before, index ) ) != -1 ) {
+ while( (index = find( before, index, TRUE, len ) ) != -1 ) {
if ( num ) {
int msize = index - movestart;
if ( msize > 0 ) {
@@ -1681,7 +1685,7 @@ QCString &QCString::replace( const char
uint indices[4096];
uint pos = 0;
while( pos < 4095 ) {
- index = find(before, index);
+ index = find(before, index, TRUE, len);
if ( index == -1 )
break;
indices[pos++] = index;
_______________________________________________
KMail Developers mailing list
kmail@mail.kde.org
http://mail.kde.org/mailman/listinfo/kmail
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic