summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuthu Subramanian <sumuthu@collabora.com>2014-02-13 21:49:18 +0530
committerMuthu Subramanian <sumuthu@collabora.com>2014-02-13 21:49:18 +0530
commit9b172206c4054be233f3b363710b90aeb925ec9d (patch)
tree057262891a6f9ea3054b9a11b15e6a82b206eed8
parentf2fa51c49bebd9ca0af5d61827b663c99a4ac5c3 (diff)
Move string hash function into String class.
Change-Id: If229f3a8c4b4fd1e5f0c28618e29eded7b7853da
-rw-r--r--sal/inc/rtl/string.h18
-rw-r--r--sal/inc/rtl/string.hxx13
-rw-r--r--sal/inc/rtl/ustring.h18
-rw-r--r--sal/rtl/source/strtmpl.cxx13
-rw-r--r--sal/util/sal.map1
-rw-r--r--sd/source/core/sdpage2.cxx12
6 files changed, 64 insertions, 11 deletions
diff --git a/sal/inc/rtl/string.h b/sal/inc/rtl/string.h
index 9f3c69a0bcc4..3def4c1c2a05 100644
--- a/sal/inc/rtl/string.h
+++ b/sal/inc/rtl/string.h
@@ -277,6 +277,24 @@ 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 cbd4b9a1b043..4b7b072cb398 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -866,6 +866,19 @@ 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
+ */
+ 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 0352e59b0e33..24a7dd8cdeeb 100644
--- a/sal/inc/rtl/ustring.h
+++ b/sal/inc/rtl/ustring.h
@@ -551,6 +551,24 @@ 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/rtl/source/strtmpl.cxx b/sal/rtl/source/strtmpl.cxx
index f9d7a5ef59a7..9b8fa51f69b7 100644
--- a/sal/rtl/source/strtmpl.cxx
+++ b/sal/rtl/source/strtmpl.cxx
@@ -272,6 +272,19 @@ 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()
diff --git a/sal/util/sal.map b/sal/util/sal.map
index ade61cdaffc2..83d824c7f513 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -221,6 +221,7 @@ UDK_3_0_0 {
rtl_str_shortenedCompareIgnoreAsciiCase_WithLength;
rtl_str_hashCode;
rtl_str_hashCode_WithLength;
+ rtl_str_hashCode64_WithLength;
rtl_str_indexOfChar;
rtl_str_indexOfChar_WithLength;
rtl_str_indexOfStr;
diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx
index f61cab070c40..37b16e2b41ae 100644
--- a/sd/source/core/sdpage2.cxx
+++ b/sd/source/core/sdpage2.cxx
@@ -54,16 +54,6 @@ using namespace ::com::sun::star::office;
extern void NotifyDocumentEvent( SdDrawDocument* pDocument, const rtl::OUString& rEventName, const Reference< XInterface >& xSource );
-static sal_uInt64 lcl_getHash( OString aString )
-{
- sal_Int32 len = aString.getLength();
- sal_uInt64 nHash = 0;
-
- for( sal_Int32 i = 0; i < len; i++ )
- nHash = (nHash << 5) - nHash + aString[i];
- return nHash;
-}
-
/*************************************************************************
|*
|* SetPresentationLayout, setzt: Layoutnamen, Masterpage-Verkn�pfung und
@@ -611,7 +601,7 @@ OString SdPage::stringify() const
sal_uInt64 SdPage::getHash() const
{
- return lcl_getHash( stringify() );
+ return stringify().hashCode64();
}