Review Request: little faster sycoca

Rolf Eike Beer kde at opensource.sf-tec.de
Wed Sep 28 21:05:09 BST 2011


Am Mittwoch, 28. September 2011, 15:47:25 schrieb Josef Weidendorfer:
> On Wednesday 28 September 2011, Jaime Torres Amate wrote:

> > and the removal of a for loop (I'm checking it this has been this way
> > since the beginning, or if fixing it makes other things faster) as Rolf
> > has pointed.
> 
> I do not see how that loop can be removed. He probably misread the inner
> condition of the first loop as "if (pos < 1 ", but it is actually
> "if (pos < entry.length", and pos can be any position in the string.

I meant this:

    if (inPos < 0) {
        pos = -inPos-1;
        for(KSycocaDictStringList::const_iterator it = stringlist-
>constBegin(); it != stringlist->constEnd(); ++it)
        {
            string_entry* entry = *it;
            register int l = entry->length;
            if (pos < l && pos != 0) {
                ...
            }
        }

What happens if inPos is -1? pos becomes 0 then. Then we iterate over the 
whole list just to do "if (... && pos != 0)" which will never be true. So for 
this case (inPos == -1) the whole function can be avoided at all as it will 
never return anything else but 0. So the initial check of the function should 
IMHO be:

    if (inPos == 0 || inPos == -1)
        return 0;

Eike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20110928/ddaf37e1/attachment.sig>


More information about the kde-core-devel mailing list