Difference between revisions of "Performance/Improver performance about string"
Zengliangjun (Talk | contribs) (Created page with '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_inte…') |
Zengliangjun (Talk | contribs) (→About some methods:) |
||
Line 19: | Line 19: | ||
As : | As : | ||
− | + | <source lang="cpp"> | |
− | + | 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)*37 + IMPL_RTL_USTRCODE( *pStr ); | |
− | + | pStr++; | |
− | + | nLen--; | |
− | + | } | |
− | + | } | |
− | + | return h; | |
− | + | } | |
+ | </source> | ||
= About string struct design:= | = About string struct design:= |
Latest revision as of 05:38, 2 March 2010
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)*37 + 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.