QStringTemp for Qt 2.2.3

Various KDE 1.-4. Improvements

Source i (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
Become a Fan
5.0

Available as/for:
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:perator+
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:

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.


Ratings & Comments

14 Comments

fprog26

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.

aaron

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

fprog26

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.

fprog26

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

vide

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

rraab

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.

fprog26

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. =(

vide

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

vide

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.

MxCl

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?

shm

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

fprog26

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! =)

panzi

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

fprog26

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.

Pling
0 Affiliates
Details
license
version
updated
added
downloads 24h 0
mediaviews 24h 0
pageviews 24h 0

More Various KDE 1.-4. Improvements from fprog26:

POLARIS: Security enhancement for KDE
fprog26
last update date: 20 years ago

Score 5.0

QtFprot interface/usability improvement
fprog26
last update date: 20 years ago

Score 5.0

QStringTemp for KDE 3.x (CVS)
fprog26
last update date: 21 years ago

Score 5.0

Other Various KDE 1.-4. Improvements:

Slicker Debian Package for Woody
cirrusgr
last update date: 22 years ago

Score 5.0

Konqueror/kdesktop suggestion
PovMan
last update date: 22 years ago

Score 5.0

Biiig buttons
dbojan
last update date: 20 years ago

Score 5.0

Yet Another KControl
Frans
last update date: 21 years ago

Score 5.0

Next window and next/previos window
dbojan
last update date: 20 years ago

Score 5.0

Fantasie Toolbar
katoe
last update date: 19 years ago

Score 5.0