summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-02-20 09:23:20 +0530
committerMuthu Subramanian <sumuthu@collabora.com>2014-02-20 09:23:20 +0530
commit98554820e6109c3e3f4ea83bf036d9f20ef1685e (patch)
tree2c9eb80cacf5737a626c64d5b1680f899bf4895c
parentfb2c25a7b82f38fb286c25cb33fcbc5247008d26 (diff)
Stick to a single O[U]String hash function
Ported from: 042725a5dadc9f2c6368ca451b6d20046129b8af Change-Id: I87f11d9101e21bdadaaffb719a762d0030639cb1
-rw-r--r--sal/inc/rtl/string.h18
-rw-r--r--sal/inc/rtl/string.hxx15
-rw-r--r--sal/inc/rtl/ustring.h18
-rw-r--r--sal/inc/rtl/ustring.hxx15
-rw-r--r--sal/rtl/source/strtmpl.cxx64
-rw-r--r--sal/util/sal.map6
-rw-r--r--sd/inc/sdpage.hxx2
-rw-r--r--sd/source/core/sdpage2.cxx4
-rw-r--r--sd/source/core/stlpool.cxx2
-rw-r--r--svl/inc/svl/itemset.hxx2
-rw-r--r--svl/source/items/itemset.cxx4
11 files changed, 12 insertions, 138 deletions
diff --git a/sal/inc/rtl/string.h b/sal/inc/rtl/string.h
index 3def4c1c2a05..9f3c69a0bcc4 100644
--- a/sal/inc/rtl/string.h
+++ b/sal/inc/rtl/string.h
@@ -277,24 +277,6 @@ SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_hashCode(
SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_hashCode_WithLength(
const sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
-/** Return a hash code (64bit) for a string.
-
- It is not allowed to store the hash code persistently, because later
- versions could return other hash codes.
-
- @param str
- a string. Need not be null-terminated, but must be at least as long as
- the specified len.
-
- @param len
- the length of the string.
-
- @return
- a hash code for the given string.
- */
-SAL_DLLPUBLIC sal_uInt64 SAL_CALL rtl_str_hashCode64_WithLength(
- const sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
-
/** Search for the first occurrence of a character within a string.
The string must be null-terminated.
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index e9a9342ef4fa..cbd4b9a1b043 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -866,21 +866,6 @@ public:
}
/**
- Returns a 64bit hash of the string data.
- This hashes the entire data, while hashCode would do sampling for larger string sizes.
-
- @return a hash code value of the string data
-
- @see hashCode() for simple hashes
-
- @since LibreOffice 4.3
- */
- sal_uInt64 hashCode64() const SAL_THROW(())
- {
- return rtl_str_hashCode64_WithLength( pData->buffer, pData->length );
- }
-
- /**
Returns a hashcode for this string.
@return a hash code value for this object.
diff --git a/sal/inc/rtl/ustring.h b/sal/inc/rtl/ustring.h
index 24a7dd8cdeeb..0352e59b0e33 100644
--- a/sal/inc/rtl/ustring.h
+++ b/sal/inc/rtl/ustring.h
@@ -551,24 +551,6 @@ SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_ustr_hashCode(
SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_ustr_hashCode_WithLength(
const sal_Unicode * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
-/** Return a hash code (64bit) for a string.
-
- It is not allowed to store the hash code persistently, because later
- versions could return other hash codes.
-
- @param str
- a string. Need not be null-terminated, but must be at least as long as
- the specified len.
-
- @param len
- the length of the string.
-
- @return
- a hash code for the given string.
- */
-SAL_DLLPUBLIC sal_uInt64 SAL_CALL rtl_ustr_hashCode64_WithLength(
- const sal_Unicode * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
-
/** Search for the first occurrence of a character within a string.
The string must be null-terminated.
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index 1f75101f08d7..36295116dbe9 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -1168,21 +1168,6 @@ public:
}
/**
- Returns a 64bit hash of the string data.
- This hashes the entire data, while hashCode would do sampling for larger string sizes.
-
- @return a hash code value of the string data
-
- @see hashCode() for simple hashes
-
- @since LibreOffice 4.3
- */
- sal_uInt64 hashCode64() const SAL_THROW(())
- {
- return rtl_ustr_hashCode64_WithLength( pData->buffer, pData->length );
- }
-
- /**
Returns a hashcode for this string.
@return a hash code value for this object.
diff --git a/sal/rtl/source/strtmpl.cxx b/sal/rtl/source/strtmpl.cxx
index 9b8fa51f69b7..3ba2eafe91c3 100644
--- a/sal/rtl/source/strtmpl.cxx
+++ b/sal/rtl/source/strtmpl.cxx
@@ -272,72 +272,18 @@ 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_Int32 h = nLen;
-
- if ( nLen < 256 )
- {
- while ( nLen > 0 )
- {
- h = (h*37) + IMPL_RTL_USTRCODE( *pStr );
- pStr++;
- nLen--;
- }
- }
- else
+ sal_uInt32 h = static_cast<sal_uInt32>(nLen);
+ 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*39) + IMPL_RTL_USTRCODE( *pStr );
+ h = (h*37U) + IMPL_RTL_USTRCODE( *pStr );
pStr++;
- h = (h*39) + IMPL_RTL_USTRCODE( *pStr );
- pStr++;
- h = (h*39) + IMPL_RTL_USTRCODE( *pStr );
- pStr++;
-
- if ( nLen < 32 )
- nSkip = nLen / 4;
- else
- nSkip = nLen / 8;
- nLen -= 8;
- while ( nLen > 0 )
- {
- h = (h*39) + IMPL_RTL_USTRCODE( *pStr );
- pStr += nSkip;
- nLen -= nSkip;
- }
-
- h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
- pEndStr++;
- h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
- pEndStr++;
- h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
- pEndStr++;
- h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
- pEndStr++;
- h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
+ nLen--;
}
-
- return h;
+ return static_cast<sal_Int32>(h);
}
/* ----------------------------------------------------------------------- */
diff --git a/sal/util/sal.map b/sal/util/sal.map
index 7ab421fd089b..ade61cdaffc2 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -652,12 +652,6 @@ LIBO_UDK_4.0 { # symbols available in >= LibO 4.0
rtl_uString_newReplaceAllFromIndex;
} LIBO_UDK_3.6;
-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;
diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx
index 0c99930960a4..422b667bc1f2 100644
--- a/sd/inc/sdpage.hxx
+++ b/sd/inc/sdpage.hxx
@@ -382,7 +382,7 @@ public:
void removeAnnotation( const ::com::sun::star::uno::Reference< ::com::sun::star::office::XAnnotation >& xAnnotation );
const sd::AnnotationVector& getAnnotations() const { return maAnnotations; }
bool hasAnnotations() const { return !maAnnotations.empty(); }
- sal_uInt64 getHash() const;
+ sal_Int32 getHash() const;
virtual OString stringify() const;
diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx
index 37b16e2b41ae..b1475e6dbc8f 100644
--- a/sd/source/core/sdpage2.cxx
+++ b/sd/source/core/sdpage2.cxx
@@ -599,9 +599,9 @@ OString SdPage::stringify() const
return aString.makeStringAndClear();
}
-sal_uInt64 SdPage::getHash() const
+sal_Int32 SdPage::getHash() const
{
- return stringify().hashCode64();
+ return stringify().hashCode();
}
diff --git a/sd/source/core/stlpool.cxx b/sd/source/core/stlpool.cxx
index bf8d0c31017c..ea4d5cf10b02 100644
--- a/sd/source/core/stlpool.cxx
+++ b/sd/source/core/stlpool.cxx
@@ -674,7 +674,7 @@ void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily
SfxStyleSheetBase* pExistingSheet = Find(aName, eFamily);
if( pExistingSheet && !rRenameSuffix.isEmpty() )
{
- sal_uInt64 nHash = xSheet->GetItemSet().getHash();
+ sal_Int32 nHash = xSheet->GetItemSet().getHash();
if( pExistingSheet->GetItemSet().getHash() != nHash )
{
OUString aTmpName = aName + rRenameSuffix;
diff --git a/svl/inc/svl/itemset.hxx b/svl/inc/svl/itemset.hxx
index 89ad83d6e0cf..13b6988903a0 100644
--- a/svl/inc/svl/itemset.hxx
+++ b/svl/inc/svl/itemset.hxx
@@ -151,7 +151,7 @@ public:
virtual SvStream & Store( SvStream &, bool bDirect = false ) const;
virtual int operator==(const SfxItemSet &) const;
- virtual sal_uInt64 getHash() const;
+ sal_Int32 getHash() const;
virtual OString stringify() const;
};
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index 0037552668c2..aa1a0ac996f0 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -2054,9 +2054,9 @@ SfxItemSet *SfxAllItemSet::Clone(sal_Bool bItems, SfxItemPool *pToPool ) const
// -----------------------------------------------------------------------
-sal_uInt64 SfxItemSet::getHash() const
+sal_Int32 SfxItemSet::getHash() const
{
- return stringify().hashCode64();
+ return stringify().hashCode();
}
// -----------------------------------------------------------------------