KiCad PCB EDA Suite
Loading...
Searching...
No Matches
allegro_db.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright Quilter
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include "convert/allegro_db.h"
22
23#include <algorithm>
24
26
27using namespace ALLEGRO;
28
29
30void BRD_DB::ReserveCapacity( size_t aObjectCount, size_t aStringCount, size_t aFileSize )
31{
32 // The counts come from the file header, so clamp them to what the file could hold. A fixed
33 // ceiling starves real designs and costs a full rehash of the key map at every doubling
34 constexpr size_t minBlockBytes = 16;
35 constexpr size_t minStringBytes = 2;
36
37 aObjectCount = std::min( aObjectCount, aFileSize / minBlockBytes );
38 aStringCount = std::min( aStringCount, aFileSize / minStringBytes );
39
40 m_Blocks.reserve( aObjectCount );
41 m_ObjectKeyMap.reserve( aObjectCount );
42 m_StringTable.reserve( aStringCount );
43}
44
45
46void BRD_DB::InsertBlock( std::unique_ptr<BLOCK_BASE> aBlock )
47{
48 if( aBlock->GetKey() != 0 )
49 m_ObjectKeyMap[aBlock->GetKey()] = aBlock.get();
50
51 m_Blocks.push_back( std::move( aBlock ) );
52}
53
54
void ReserveCapacity(size_t aObjectCount, size_t aStringCount, size_t aFileSize)
Pre-allocate storage for the expected number of objects and strings.
std::unordered_map< uint32_t, wxString > m_StringTable
Definition allegro_db.h:89
std::unordered_map< uint32_t, BLOCK_BASE * > m_ObjectKeyMap
Definition allegro_db.h:88
FMT_VER m_FmtVer
Definition allegro_db.h:84
std::vector< std::unique_ptr< BLOCK_BASE > > m_Blocks
Definition allegro_db.h:87
void InsertBlock(std::unique_ptr< BLOCK_BASE > aBlock)
FMT_VER
The format of an Allegro file.