Allow most libraries to reserve capacity for their database.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-12-31 10:48:52 +01:00
parent db2eb0c3fa
commit 4d3dc28606
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
5 changed files with 13 additions and 5 deletions

View File

@ -11,7 +11,8 @@ namespace CreatureLib::Library {
std::unordered_map<std::string, const AttackData*> _attacks; std::unordered_map<std::string, const AttackData*> _attacks;
public: public:
AttackLibrary() = default; AttackLibrary(size_t initialCapacity = 32)
: _attacks(std::unordered_map<std::string, const AttackData*>(initialCapacity)){};
~AttackLibrary() { ~AttackLibrary() {
for (auto attack : _attacks) { for (auto attack : _attacks) {

View File

@ -12,8 +12,11 @@ namespace CreatureLib::Library {
std::unordered_map<std::string, GrowthRate*> _growthRates; std::unordered_map<std::string, GrowthRate*> _growthRates;
public: public:
~GrowthRateLibrary(){ GrowthRateLibrary(size_t initialCapacity = 10)
for (auto gr: _growthRates){ : _growthRates(std::unordered_map<std::string, GrowthRate*>(initialCapacity)) {}
~GrowthRateLibrary() {
for (auto gr : _growthRates) {
delete gr.second; delete gr.second;
} }
} }

View File

@ -11,7 +11,8 @@ namespace CreatureLib::Library {
std::unordered_map<std::string, const Item*> _items; std::unordered_map<std::string, const Item*> _items;
public: public:
ItemLibrary() = default; ItemLibrary(size_t initialCapacity = 32)
: _items(std::unordered_map<std::string, const Item*>(initialCapacity)){};
~ItemLibrary() { _items.clear(); } ~ItemLibrary() { _items.clear(); }
[[nodiscard]] const Item* GetItem(const std::string& name) const; [[nodiscard]] const Item* GetItem(const std::string& name) const;

View File

@ -11,7 +11,8 @@ namespace CreatureLib::Library {
std::unordered_map<std::string, const CreatureSpecies*> _species; std::unordered_map<std::string, const CreatureSpecies*> _species;
public: public:
SpeciesLibrary() = default; SpeciesLibrary(size_t initialCapacity = 32)
: _species(std::unordered_map<std::string, const CreatureSpecies*>(initialCapacity)){};
~SpeciesLibrary() { ~SpeciesLibrary() {
for (auto s : _species) for (auto s : _species)

View File

@ -10,6 +10,8 @@ namespace CreatureLib::Library {
std::vector<std::vector<float>> _effectiveness; std::vector<std::vector<float>> _effectiveness;
public: public:
TypeLibrary(size_t initialCapacity = 20) : _types(std::unordered_map<std::string, uint8_t>(initialCapacity)) {}
uint8_t GetTypeId(const std::string& s) const; uint8_t GetTypeId(const std::string& s) const;
float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const; float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const;
float GetEffectiveness(uint8_t attacking, const std::vector<uint8_t>& defensive) const; float GetEffectiveness(uint8_t attacking, const std::vector<uint8_t>& defensive) const;