
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
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.
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.
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.
fprog26
16 years ago
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
Report
fprog26
16 years ago
./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
fprog26
16 years ago
I will post it tomorrow. ;-)
Report
vide
16 years ago
Report
rraab
16 years ago
Report
vide
16 years ago
Report
MxCl
16 years ago
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
fprog26
16 years ago
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
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
Report
fprog26
16 years ago
"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
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
fprog26
16 years ago
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