QStringTemp for Qt 2.2.3

Various KDE 1.-4. Improvements

Source (link to git-repo or to original if based on someone elses unmodified work): Add the source-code for this project on opencode.net

2
5 .0
Description:

Improve speed performance of QString
while keeping the syntax readable as is.

e.g.
QStringTemp tmp( 4096 );
QString s = tmp + a + b + c + d;

OR

uint sz = a::length() + b::length() +
c::length() + d::length();
QStringTemp tmp( sz );
QString s = tmp + a + b + c + d;

Another way is to modify the
QString::operator+
to use QStringTemp implicitely.

Performance increase from few ms to 4x faster depending on the buffer size
and the size of each string.

See test cases screenshots
for various buffer size algorithms.

The Qt version of this code may be released under the GPL/QPL, if needed.
Last changelog:

16 years ago

0.1: Initial version for VCL/AnsiString and VCL/WideString
0.2: Revised for MFC/CString
0.3: Revised for Qt2-Win32/QString
0.4: Revised for Qt2-Linux/QString
0.5: Added Makefile
1.0: Official release.

C

fprog26

16 years ago

The version for current KDE 3.x CVS
can be found here.

http://kde-apps.org/content/show.php?content=12191

QStringTemp for Qt 2.2.3 had
14 comments up to date.

Report

aaron

16 years ago

how do you apply this patch? i'm interested in using this.

Report

C

fprog26

16 years ago

You only need in the tarball
./qtools/qstringtemp.h

In your KDE CVS dir
change ./qtools/qstring.h

You make:

virtual ~QString()

and you change in front of
QString( int size, bool dummy );

private: --> protected:

I had difficulty compiling
qtools from KDE webcvs.

Maybe someone can point me
to a working out-of-the-box
qtools KDE3 tarball ?

It works perfectly with Qt 2.2.3 (Win32/Linux) provided in the tarball.

Fred.

Report

C

fprog26

16 years ago

I got a working version for KDE 3.x =)
I will post it tomorrow. ;-)

Report

vide

16 years ago

Optimizations are nice things but..why posting it here? I think your patch should go to a kde-devel mailing list, not to www.kde-apps.org

Report

rraab

16 years ago

Why not post it here? These is a whole section devoted to improvements, not just gui. This improves speed and readability. In addition, it may spark others to come up with similar ideas.

Report

vide

16 years ago

Ok, so let's close kde development mailing lists and let's all propose patches on kde-apps.org and discuss about them in comments. And let's see what happens.

Report

MxCl

16 years ago

Stop it. This guy has produced some excellent work. I think this is far more worthy of being here than the miriad of service .desktop files that are polluting kde-apps at the moment.

I agree it is not really the correct place, but that doesn't excuse your behavior. It's just rude.

And to the author, an excellent class, I will probably try to build on the concepts and make such a class for my apps. I hope it gets into Qt. One thing that occured to me while reading the description, is that this appears to be a good place for the compiler to try an make the optimisation of operator+ to operator+= itself. I wonder why it isn't done?

Report

C

fprog26

16 years ago

I guess I have to sign up to all those mailling list.

Also I needed a place where I could get minimal space for the tarball and output screenshots.

It's also easier to get more attention here, than on the mailing list where your post get lost in the dust after a month. =(

Report

vide

16 years ago

No, you haven't, you can send your mail even without being subscribed, and you can send your patch there to be examined and discussed by all other KDE developers. This (kde-apps.org) is definitely a place for end-users who wants to find the most suitable KDE application for their needs, not a place for developer to discuss about improvements in the rough code.

Ok, talking about UI improvements is a totally different thing, but in your case there's no UI at all. UI is used by user :) directly, code is managed by developers directly.

Just my 2 cents

Report

shm

16 years ago

to the kde-optimize mailing list.....

Report

C

fprog26

16 years ago

Basically, the algorithm is a
"Temporary String Proxy Design Pattern"

http://www.google.com/search?q=design+pattern+proxy

http://www.dofactory.com/patterns/PatternProxy.aspx

http://www.javaworld.com/javaworld/jw-02-2002/jw-0222-designpatterns.html?

http://www.openloop.com/softwareEngineering/patterns/designPattern/dPattern_Proxy.htm

The idea is that the QStringTemp proxy
has the same behavior than QString.

The difference is that we "know" that it's a QStringTemp not a QString;
therefore, we can leverage this opportunity to optimize.

In other words, we are doing this:
inline QStringTemp& operator+( T )
{
QString::operator+=( T );
return *this;
}

So, instead of being tedious
and write by hand:

uint sz = a::length() + b::length() + c::length() + d::length();

QString tmp( (int)sz, true );

tmp += a;
tmp += b;
tmp += c;
tmp += d;

QString s = tmp;

We simply write:

uint sz = a::length() + b::length() + c::length() + d::length();

QStringTemp tmp( (int)sz, true );
QString s = tmp + a + b + c + d;

which WAY MORE NATURAL!

The thing is that, if QString::operator+( T ) always returned a QStringTemp and would always make a good estimate,
see in the screenshot the section: "WITHOUT KNOWING QStringTemp buffer size in advance"

Then you would simply have to recompile KDE and get the improvement all over the place!

Needs a bit of tweaking around:

#ifndef QStringTempSize

#ifndef QStringTempShift
#define QStringTempShift 3
#endif

#define QStringTempSize( sz ) ( ((sz) + (sz) >> (QStringTempShift)) | 16 )

//#define QStringTempSize( sz ) ( ((sz) + (sz) >> 3) | 16 )
#endif

Needs more benchmarking on various String concatenation scenarios.

In the meanwhile,
Enjoy!

Long life to KDE! =)

Report

panzi

16 years ago

Isn't this similar to following?
QString result;
QTextOStream(&result) << "pi = " << 3.14;

The only diff. I can see is, that << is used instead of + and I can't find a constructor to set the initial stringsize of QStrings. http://doc.trolltech.com/3.3/qstring.html

Report

C

fprog26

16 years ago

QString(int buffer_length, bool dummy);
is currently private, you have to change it to public or protected.
You also have to put ~QString to be a virtual function.

http://doc.trolltech.com/3.2/qtextostream.html
"QTextOStream class is a convenience class for output streams, providing a shorthand for creating simple output QTextStreams without having to pass a mode argument to the constructor."

Where QStringTemp is just a proxy QString, which is used as a QString.
It does NOT have to be an output stream.

Report

16 years ago

0.1: Initial version for VCL/AnsiString and VCL/WideString
0.2: Revised for MFC/CString
0.3: Revised for Qt2-Win32/QString
0.4: Revised for Qt2-Linux/QString
0.5: Added Makefile
1.0: Official release.

12345678910
product-maker Base: 4 x 5.0 Ratings
Be the first to comment
kristensjones
Nov 27 2019
williamchansen
Nov 27 2019
File (click to download) Version Description PackagetypeArchitecture Downloads Date Filesize DL OCS-Install MD5SUM
*Needs pling-store or ocs-url to install things
Pling
0 Affiliates
Details
license
version
updated Apr 23 2004
added Apr 21 2004
downloads 24h
0
mediaviews 24h 0
pageviews 24h 0