28#include <osl/diagnose.h>
45 static void *
operator new (size_t,
void *
p) {
return p; }
46 static void operator delete (
void *,
void *) {}
48 explicit Entry (std::shared_ptr<PageData>
const & rxPage, sal_uInt32 nOffset)
59 rtl_cache_type * m_entry_cache;
62 static EntryCache &
get();
64 Entry *
create (std::shared_ptr<PageData>
const & rxPage, sal_uInt32 nOffset);
66 void destroy (
Entry * entry);
75EntryCache & EntryCache::get()
77 static EntryCache g_entry_cache;
81EntryCache::EntryCache()
83 m_entry_cache = rtl_cache_create (
84 "store_cache_entry_cache",
96EntryCache::~EntryCache()
98 rtl_cache_destroy (m_entry_cache);
99 m_entry_cache =
nullptr;
102Entry * EntryCache::create (std::shared_ptr<PageData>
const & rxPage, sal_uInt32 nOffset)
104 void * pAddr = rtl_cache_alloc (m_entry_cache);
105 if (pAddr !=
nullptr)
108 return new(pAddr)
Entry (rxPage, nOffset);
113void EntryCache::destroy (
Entry * entry)
115 if (entry !=
nullptr)
121 rtl_cache_free (m_entry_cache, entry);
132 if constexpr (
sizeof(
n) == 8)
134 if (
n & 0xffffffff00000000)
167PageCache::PageCache (sal_uInt16 nPageSize)
168 : m_hash_table (m_hash_table_0),
169 m_hash_size (theTableSize),
170 m_hash_shift (
highbit(m_hash_size) - 1),
171 m_page_shift (
highbit(nPageSize) - 1),
177 static_assert(theSize ==
theTableSize,
"must be equal");
184 for (
i = 0;
i <
n;
i++)
188 while (entry !=
nullptr)
192 EntryCache::get().destroy (entry);
198 double ave = s_x / double(
n);
199 SAL_INFO(
"store",
"avg hash chain length: " << ave);
213 std::size_t new_bytes = new_size *
sizeof(
Entry*);
214 Entry ** new_table =
static_cast<Entry**
>(std::malloc(new_bytes));
216 if (new_table ==
nullptr)
226 << old_size <<
" new_size: " << new_size <<
"]");
228 memset (new_table, 0, new_bytes);
235 for (
i = 0;
i < old_size;
i++)
237 Entry * curr = old_table[
i];
238 while (curr !=
nullptr)
246 old_table[
i] =
nullptr;
251 std::free (old_table);
258 while (entry !=
nullptr)
269 for (; ave > 4; new_size *= 2, ave /= 2)
279 OSL_PRECOND(!(nOffset ==
STORE_PAGE_NULL),
"store::PageCache::lookupPageAt(): invalid Offset");
285 if (entry !=
nullptr)
303 PageData const * pagedata = rxPage.get();
304 OSL_PRECOND(!(pagedata ==
nullptr),
"store::PageCache::insertPageAt(): invalid Page");
305 if (pagedata ==
nullptr)
308 sal_uInt32
const offset = pagedata->
location();
309 OSL_PRECOND(!(nOffset != offset),
"store::PageCache::insertPageAt(): inconsistent Offset");
310 if (nOffset != offset)
313 OSL_PRECOND(!(nOffset ==
STORE_PAGE_NULL),
"store::PageCache::insertPageAt(): invalid Offset");
317 Entry * entry = EntryCache::get().create (rxPage, nOffset);
318 if (entry !=
nullptr)
335 PageData const * pagedata = rxPage.get();
336 OSL_PRECOND(!(pagedata ==
nullptr),
"store::PageCache::updatePageAt(): invalid Page");
337 if (pagedata ==
nullptr)
340 sal_uInt32
const offset = pagedata->
location();
341 OSL_PRECOND(!(nOffset != offset),
"store::PageCache::updatePageAt(): inconsistent Offset");
342 if (nOffset != offset)
345 OSL_PRECOND(!(nOffset ==
STORE_PAGE_NULL),
"store::PageCache::updatePageAt(): invalid Offset");
351 if (entry !=
nullptr)
364 OSL_PRECOND(!(nOffset ==
STORE_PAGE_NULL),
"store::PageCache::removePageAt(): invalid Offset");
369 while (*ppEntry !=
nullptr)
371 if ((*ppEntry)->m_nOffset == nOffset)
374 Entry * entry = *ppEntry;
379 EntryCache::get().destroy (entry);
385 ppEntry = &((*ppEntry)->m_pNext);
403 sal_uInt16 nPageSize)
virtual ~PageCache() override
int hash_index_Impl(sal_uInt32 nOffset)
storeError lookupPageAt(std::shared_ptr< PageData > &rxPage, sal_uInt32 nOffset)
storeError updatePageAt(std::shared_ptr< PageData > const &rxPage, sal_uInt32 nOffset)
void rescale_Impl(std::size_t new_size)
static size_t const theTableSize
Entry * lookup_Impl(Entry *entry, sal_uInt32 nOffset)
Entry * m_hash_table_0[theTableSize]
storeError insertPageAt(std::shared_ptr< PageData > const &rxPage, sal_uInt32 nOffset)
storeError removePageAt(sal_uInt32 nOffset)
#define SAL_INFO(area, stream)
#define SAL_N_ELEMENTS(arr)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
Old OStorePageCache implementation.
storeError PageCache_createInstance(rtl::Reference< store::PageCache > &rxCache, sal_uInt16 nPageSize)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
static int highbit(std::size_t n)
Entry(std::shared_ptr< PageData > const &rxPage, sal_uInt32 nOffset)
std::shared_ptr< PageData > m_xPage
sal_uInt32 location() const
location.
storeError
Error Code enumeration.
@ store_E_InvalidParameter