diff options
Diffstat (limited to 'sal/rtl/source/hash.cxx')
-rw-r--r-- | sal/rtl/source/hash.cxx | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/sal/rtl/source/hash.cxx b/sal/rtl/source/hash.cxx index 6ffdc4140..63de2b4f9 100644 --- a/sal/rtl/source/hash.cxx +++ b/sal/rtl/source/hash.cxx @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: hash.cxx,v $ - * $Revision: 1.5 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify @@ -39,52 +36,51 @@ #include <hash_set> namespace { - struct UStringHash - { - size_t operator()(rtl_uString * const &rString) const - { return (size_t)rtl_ustr_hashCode_WithLength( rString->buffer, rString->length ); } - }; - struct UStringEqual - { - sal_Bool operator() ( rtl_uString * const &pStringA, - rtl_uString * const &pStringB) const - { - if (pStringA == pStringB) - return true; - if (pStringA->length != pStringB->length) - return false; - return !rtl_ustr_compare_WithLength( pStringA->buffer, pStringA->length, - pStringB->buffer, pStringB->length); - } - }; -} -typedef std::hash_set< rtl_uString *, UStringHash, UStringEqual, - rtl::Allocator<rtl_uString *> > UniqueHash; +struct UStringHash +{ + size_t operator()(rtl_uString * const &rString) const + { return (size_t)rtl_ustr_hashCode_WithLength( rString->buffer, rString->length ); } +}; -struct StringHashTableImpl : public UniqueHash +struct UStringEqual { - StringHashTableImpl(sal_uInt32 nSize) : UniqueHash( nSize ) {} + sal_Bool operator() ( rtl_uString * const &pStringA, + rtl_uString * const &pStringB) const + { + if (pStringA == pStringB) + return true; + if (pStringA->length != pStringB->length) + return false; + return !rtl_ustr_compare_WithLength( pStringA->buffer, pStringA->length, + pStringB->buffer, pStringB->length); + } }; +typedef std::hash_set< rtl_uString *, UStringHash, UStringEqual, + rtl::Allocator<rtl_uString *> > StringHashTable; + StringHashTable * -rtl_str_hash_new (sal_uInt32 nSize) +getHashTable () { - return new StringHashTableImpl (nSize); + static StringHashTable *pInternPool = NULL; + if (pInternPool == NULL) { + static StringHashTable aImpl(1024); + pInternPool = &aImpl; + } + return pInternPool; } -void -rtl_str_hash_free (StringHashTable *pHash) -{ - delete pHash; } +extern "C" { + rtl_uString * -rtl_str_hash_intern (StringHashTable *pHash, - rtl_uString *pString, +rtl_str_hash_intern (rtl_uString *pString, int can_return) { - UniqueHash::iterator aIter; + StringHashTable *pHash = getHashTable(); + StringHashTable::iterator aIter; aIter = pHash->find(pString); if (aIter != pHash->end()) { @@ -109,8 +105,9 @@ rtl_str_hash_intern (StringHashTable *pHash, } void -rtl_str_hash_remove (StringHashTable *pHash, - rtl_uString *pString) +rtl_str_hash_remove (rtl_uString *pString) { - pHash->erase(pString); + getHashTable()->erase(pString); +} + } |