diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-02-18 12:49:50 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-02-18 13:08:58 +0100 |
commit | 042725a5dadc9f2c6368ca451b6d20046129b8af (patch) | |
tree | c43b1359bcef882985a06303551a227825d1e5a8 /sd | |
parent | f2529fc7441ced32daef09c0ca767080998d1792 (diff) |
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
Diffstat (limited to 'sd')
-rw-r--r-- | sd/inc/sdpage.hxx | 2 | ||||
-rw-r--r-- | sd/source/core/sdpage2.cxx | 4 | ||||
-rw-r--r-- | sd/source/core/stlpool.cxx | 2 |
3 files changed, 4 insertions, 4 deletions
diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx index c08b48f71bd1..40a4dcf15358 100644 --- a/sd/inc/sdpage.hxx +++ b/sd/inc/sdpage.hxx @@ -378,7 +378,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 a870895dd32c..3f5615056b0b 100644 --- a/sd/source/core/sdpage2.cxx +++ b/sd/source/core/sdpage2.cxx @@ -603,9 +603,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 b1bad09de780..387fb8f2f5a5 100644 --- a/sd/source/core/stlpool.cxx +++ b/sd/source/core/stlpool.cxx @@ -650,7 +650,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; |