From 042725a5dadc9f2c6368ca451b6d20046129b8af Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 18 Feb 2014 12:49:50 +0100 Subject: Stick to a single O[U]String hash function 8f8bc0dcf3bc253ae49159d52db049767f476ced "Move string hash function into String class" had introduced a new getHash64 that, besides returning sal_uInt64 instead of just sal_Int32, didn't do sampling of only a handful of characters, but always computed the hash over all characters (as the usage in SfxItemSet and SdPage appears to require for either performance or approximated correctness). However, it would be advantageous to keep the stable URE interface as small as possible. Now, O(1) sampling was apparently considered state of the art when the rtl string classes were first created, closely copying java.lang.String, which at that time demanded sampling for hashCode(), too---but never sampling more than 15 characters, with the obvious (in hindsight, at least) performance catastrophes, so they changed it to O(n) somewhere along the way. Based on that, this commit changes the existing hash functions to not do sampling any more, and removes the newly introduced -64 variants again. (Where the extended value range of sal_uInt64 compared to sal_Int32 was hopefully not vital to the existing uses.) The old implementation used sampling only for strings of length >= 256, so I did a "make check" build with an instrumented hash function that flagged all uses with inputs of length >= 256, and grepped workdir/{Cppunit,Junit,Python}Test for hits. Of the 2849 hits encountered, 2845 where in the range from 256 to 295 characters, and only the remaining four where of 2472 characters. Those four were from CppunitTest_sc_subsequent_filters_test, importing long text into a cell, causing ScDocumentImport::setStringCell to call svl::SharedStringPool::intern, which internally uses an unordered_set. These results appear to justify the change. Change-Id: I78fcc3b0f07389bdf36a21701b95a1ff0a0d970f --- sal/rtl/strtmpl.cxx | 57 +++-------------------------------------------------- sal/util/sal.map | 6 ------ 2 files changed, 3 insertions(+), 60 deletions(-) (limited to 'sal') diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx index a9eb665e9216..957609692449 100644 --- a/sal/rtl/strtmpl.cxx +++ b/sal/rtl/strtmpl.cxx @@ -252,68 +252,17 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode )( const IMPL_RTL_STRCODE* pStr ) /* ----------------------------------------------------------------------- */ -sal_uInt64 SAL_CALL IMPL_RTL_STRNAME( hashCode64_WithLength )( const IMPL_RTL_STRCODE* pStr, - sal_Int32 nLen ) - SAL_THROW_EXTERN_C() -{ - sal_uInt64 nHash = 0; - - for( sal_Int32 i = 0; i < nLen; i++ ) - nHash = (nHash << 5) - nHash + *pStr++; - return nHash; -} - -/* ----------------------------------------------------------------------- */ - sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCODE* pStr, sal_Int32 nLen ) SAL_THROW_EXTERN_C() { sal_uInt32 h = static_cast(nLen); - - if ( nLen < 256 ) - { - while ( nLen > 0 ) - { - h = (h*37U) + IMPL_RTL_USTRCODE( *pStr ); - pStr++; - nLen--; - } - } - else + while ( nLen > 0 ) { - sal_Int32 nSkip; - const IMPL_RTL_STRCODE* pEndStr = pStr+nLen-5; - - /* only sample some characters */ - /* the first 3, some characters between, and the last 5 */ - h = (h*39U) + IMPL_RTL_USTRCODE( *pStr ); - pStr++; - h = (h*39U) + IMPL_RTL_USTRCODE( *pStr ); - pStr++; - h = (h*39U) + IMPL_RTL_USTRCODE( *pStr ); + h = (h*37U) + IMPL_RTL_USTRCODE( *pStr ); pStr++; - - nSkip = nLen / 8; - nLen -= 8; - while ( nLen > 0 ) - { - h = (h*39U) + IMPL_RTL_USTRCODE( *pStr ); - pStr += nSkip; - nLen -= nSkip; - } - - h = (h*39U) + IMPL_RTL_USTRCODE( *pEndStr ); - pEndStr++; - h = (h*39U) + IMPL_RTL_USTRCODE( *pEndStr ); - pEndStr++; - h = (h*39U) + IMPL_RTL_USTRCODE( *pEndStr ); - pEndStr++; - h = (h*39U) + IMPL_RTL_USTRCODE( *pEndStr ); - pEndStr++; - h = (h*39U) + IMPL_RTL_USTRCODE( *pEndStr ); + nLen--; } - return static_cast(h); } diff --git a/sal/util/sal.map b/sal/util/sal.map index 074eb7b96063..1456d6db1cf8 100644 --- a/sal/util/sal.map +++ b/sal/util/sal.map @@ -670,12 +670,6 @@ LIBO_UDK_4.2 { # symbols available in >= LibO 4.2 rtl_ustr_toUInt32; } LIBO_UDK_4.1; -LIBO_UDK_4.3 { #symbols available in >= LibO 4.3 - global: - rtl_str_hashCode64_WithLength; - rtl_ustr_hashCode64_WithLength; -} LIBO_UDK_4.2; - PRIVATE_1.0 { global: osl_detail_ObjectRegistry_storeAddresses; -- cgit