[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-optimize
Subject:    Re: improvement in Font::drawText: fix or only workaround?
From:       Stefan Heimers <stefan () heimers ! ch>
Date:       2005-03-05 9:40:55
Message-ID: 200503051040.56562.stefan () heimers ! ch
[Download RAW message or body]

Am Samstag, 5. März 2005 09.58 schrieb Simon Hausmann:

> That's not a problem. QConstString doesn't create a copy of the data,
> it's cheap to construct and destruct.

Hi,

It's still creating a new object, which is not negible even if it's not 
that bad.

If it's not possible to fix things in Qt, I would recommend checking the 
size of the string and only creating a substring if the original qstr 
is larger than a certain size. You could guess that size to be about 
50kB, or do some more tests to see at which exact size the workaround 
starts being better than the original code.

Don't do a qstr.length(), that's another unnecessary function call. 
Font::drawText is called with a length argument "int slen". Use this, 
so you only need to compare two integers to decide if the copy is worth 
creating, which is really cheap.

My proposed code:

// TODO: remove this workaround in case the QPainter::drawText
// can be optimized
if (slen > 50000){
  // patch from  l.savernik@aon.at
  QConstString cstr = QConstString(str + pos, len);
  p->drawText( x, y, cstr.string(), 0, len, d );
}
else{
 // original code
 p->drawText( x, y, qstr, pos, len, d );
}



Stefan
_______________________________________________
Kde-optimize mailing list
Kde-optimize@kde.org
https://mail.kde.org/mailman/listinfo/kde-optimize

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic