List Info

Thread: ScInterpreter::ScPropper() Optimization?




ScInterpreter::ScPropper() Optimization?
user name
2007-04-11 15:22:31
I found some interesting code inside the function 
ScInterpreter::ScPropper() [in interpr1.cxx]. namely, there
is a while 
loop and an unnecessary subtraction is nested inside this
while loop:

see   pStr[nPos - 1]


    while( nPos < nLen )
    {
        aTmpStr.SetChar( 0, pStr[nPos-1] );        //    
<----------HERE
        if ( !ScGlobal::pCharClass->isLetter( aTmpStr, 0
) )
            pStr[nPos] = pUpr[nPos];
        else
            pStr[nPos] = pLwr[nPos];
        nPos++;
    }

This could be easily rewritten to:

    xub_StrLen nPos = 0;                   //  <---------
MODIFIED
    const xub_StrLen nLen = aStr.Len() - 1; // 
<--------- MODIFIED
   // NEED TO TEST (aStr.Len() == 0) ???
    while( nPos < nLen )
    {
        aTmpStr.SetChar( 0, pStr[nPos] );        // 
<--------- MODIFIED
        nPos++;         //  <-------------------- MOVED
HERE
        if ( !ScGlobal::pCharClass->isLetter( aTmpStr, 0
) )
            pStr[nPos] = pUpr[nPos];
        else
            pStr[nPos] = pLwr[nPos];
        // nPos++;         //   <------------------ MOVED
 BEFORE  IF
    }
    aStr.ReleaseBufferAccess( nLen + 1);  // <-----
MODIFIED
    PushString( aStr );

Is this optimization feasible?

Sincerely,

Leonard

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribesc.openoffice.org
For additional commands, e-mail: dev-helpsc.openoffice.org


Re: ScInterpreter::ScPropper() Optimization?
user name
2007-04-12 05:29:21
Leonard Mada wrote:
> I found some interesting code inside the function 
> ScInterpreter::ScPropper() [in interpr1.cxx]. namely,
there is a while 
> loop and an unnecessary subtraction is nested inside
this while loop:
> 
> see   pStr[nPos - 1]
> 
> 
>    while( nPos < nLen )
>    {
>        aTmpStr.SetChar( 0, pStr[nPos-1] );        //   
 <----------HERE
>        if ( !ScGlobal::pCharClass->isLetter(
aTmpStr, 0 ) )
>            pStr[nPos] = pUpr[nPos];
>        else
>            pStr[nPos] = pLwr[nPos];
>        nPos++;
>    }
> 
> This could be easily rewritten to:
> 
>    xub_StrLen nPos = 0;                   // 
<--------- MODIFIED
>    const xub_StrLen nLen = aStr.Len() - 1; // 
<--------- MODIFIED
>   // NEED TO TEST (aStr.Len() == 0) ???
>    while( nPos < nLen )
>    {
>        aTmpStr.SetChar( 0, pStr[nPos] );        // 
<--------- MODIFIED
>        nPos++;         //  <--------------------
MOVED HERE
>        if ( !ScGlobal::pCharClass->isLetter(
aTmpStr, 0 ) )
>            pStr[nPos] = pUpr[nPos];
>        else
>            pStr[nPos] = pLwr[nPos];
>        // nPos++;         //   <------------------
MOVED  BEFORE  IF
>    }
>    aStr.ReleaseBufferAccess( nLen + 1);  // <-----
MODIFIED
>    PushString( aStr );
> 
> Is this optimization feasible?

That wouldn't give any noticeable performance gain (probably
not even 
measurable), so let's keep the old code. Having a variable
nLen contain 
the string length, as the name suggests, is also easier to
read and 
understand.

Niklas

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribesc.openoffice.org
For additional commands, e-mail: dev-helpsc.openoffice.org


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )