/src/libreoffice/sw/inc/bparr.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <assert.h> |
23 | | |
24 | | #include "swdllapi.h" |
25 | | #include <array> |
26 | | #include <memory> |
27 | | |
28 | | struct BlockInfo; |
29 | | class BigPtrArray; |
30 | | |
31 | | class BigPtrEntry |
32 | | { |
33 | | friend class BigPtrArray; |
34 | | BlockInfo* m_pBlock; |
35 | | sal_uInt16 m_nOffset; |
36 | | public: |
37 | 44.5M | BigPtrEntry() : m_pBlock(nullptr), m_nOffset(0) {} |
38 | 0 | BigPtrEntry(BigPtrEntry const &) = default; |
39 | 44.5M | virtual ~BigPtrEntry() = default; |
40 | | BigPtrEntry & operator =(BigPtrEntry const &) = default; |
41 | | |
42 | | inline sal_Int32 GetPos() const; |
43 | | inline BigPtrArray& GetArray() const; |
44 | 0 | bool IsDisconnected() const { return m_pBlock == nullptr; } |
45 | | }; |
46 | | |
47 | | // 1000 entries per Block = a bit less than 4K |
48 | 29.5M | #define MAXENTRY 1000 |
49 | | |
50 | | // number of entries that may remain free during compression |
51 | | // this value is for the worst case; because we defined MAXBLOCK with ca 25% |
52 | | // overhead, 80% = 800 entries are enough |
53 | | // if complete compression is desired, 100 has to be specified |
54 | 567k | #define COMPRESSLVL 80 |
55 | | |
56 | | struct BlockInfo final |
57 | | { |
58 | | BigPtrArray* pBigArr; ///< in this array the block is located |
59 | | sal_Int32 nStart, nEnd; ///< start- and end index |
60 | | sal_uInt16 nElem; ///< number of elements |
61 | | std::array<BigPtrEntry*, MAXENTRY> |
62 | | mvData; ///< data block |
63 | | }; |
64 | | |
65 | | class BigPtrArray |
66 | | { |
67 | | protected: |
68 | | std::unique_ptr<BlockInfo*[]> |
69 | | m_ppInf; ///< block info |
70 | | sal_Int32 m_nSize; ///< number of elements |
71 | | sal_uInt16 m_nMaxBlock; ///< current max. number of blocks |
72 | | sal_uInt16 m_nBlock; ///< number of blocks |
73 | | mutable |
74 | | sal_uInt16 m_nCur; ///< last used block |
75 | | |
76 | | sal_uInt16 Index2Block( sal_Int32 ) const; ///< block search |
77 | | BlockInfo* InsBlock( sal_uInt16 ); ///< insert block |
78 | | void BlockDel( sal_uInt16 ); ///< some blocks were deleted |
79 | | void UpdIndex( sal_uInt16 ); ///< recalculate indices |
80 | | void ImplRemove( sal_Int32 pos, sal_Int32 n, bool bClearElement ); |
81 | | void ImplReplace( sal_Int32 idx, BigPtrEntry* pElem, bool bClearElement ); |
82 | | |
83 | | // fill all blocks |
84 | | sal_uInt16 Compress(); |
85 | | |
86 | | public: |
87 | | BigPtrArray(); |
88 | | ~BigPtrArray(); |
89 | | |
90 | 6.15M | sal_Int32 Count() const { return m_nSize; } |
91 | | |
92 | | void Insert( BigPtrEntry* p, sal_Int32 pos ); |
93 | | void Remove( sal_Int32 pos, sal_Int32 n = 1 ); |
94 | | void Move( sal_Int32 from, sal_Int32 to ); |
95 | | void Replace( sal_Int32 pos, BigPtrEntry* p); |
96 | | |
97 | | /** Speed up the complicated removal logic in SwNodes::RemoveNode. |
98 | | Returns the entry before pNotTheOne. |
99 | | */ |
100 | | BigPtrEntry* ReplaceTheOneAfter( BigPtrEntry* pNotTheOne, BigPtrEntry* pNewEntry); |
101 | | |
102 | | SW_DLLPUBLIC BigPtrEntry* operator[]( sal_Int32 ) const; |
103 | | }; |
104 | | |
105 | | inline sal_Int32 BigPtrEntry::GetPos() const |
106 | 3.05G | { |
107 | 3.05G | assert(this == m_pBlock->mvData[ m_nOffset ]); // element not in the block |
108 | 3.05G | return m_pBlock->nStart + m_nOffset; |
109 | 3.05G | } |
110 | | |
111 | | inline BigPtrArray& BigPtrEntry::GetArray() const |
112 | 574M | { |
113 | 574M | return *m_pBlock->pBigArr; |
114 | 574M | } |
115 | | |
116 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |