Performance/Improver performance about string

From Apache OpenOffice Wiki
< Performance
Revision as of 03:58, 2 March 2010 by Zengliangjun (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

I tried three methods.

About string cache:

Sometimes cache the struct 'rtl_uString' in a hash object.

That will add the cost like 'internRelease', 'rtl_ustring_intern_internal' when add a 'rtl_uString' and a 'rtl_uString' refCount is '0'.

I think it's purpose is reducing memory cost( right or no).

We can don't use the cache to improver performance.

About some methods:

Calculate the 'rtl_uString'/'rtl_String' hashCode and compare the 'rtl_uString'/'rtl_String', that is one by one. So many 'sal_Cahr'/'sal_Unicode' and many operator times.

The 'sal_Cahr'/'sal_Unicode' and 'sal_Int32' are the same data type.

We can operator the 'sal_Cahr'/'sal_Unicode' like operator 'sal_Int32', and one 'sal_Int32' is 4/2 'sal_Cahr'/'sal_Unicode' ;that will reduce the operator times.

As :

sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )
( const IMPL_RTL_STRCODE* pStr, sal_Int32 nLen )
{
    static sal_Int32 _count = sizeof(sal_Int32)/sizeof(IMPL_RTL_STRCODE);
     sal_Int32 h = nLen;
     while ( nLen > 0 )
     {
         if( nLen > _count )
         {
             h +=  (*((sal_Int32*)(void *)pStr ))*37;
             pStr+= _count;
             nLen-= _count;
         }else
         {
             h = (h)*39 + IMPL_RTL_USTRCODE( *pStr );
             pStr++;
             nLen--;
         }
     }
     return h;
}

About string struct design:

Now the struct has three members: 'refCount', 'length', 'buffer'.

Compare and calculate hash value for string that is frequent .

We can add a field it cache the string's hash value.

Some times Compare or calculate hash value; these will compare the cache value or return the cache value directly.

I 'd tried the three methods; it is not particularly evident from the time comparison.

Personal tools