Implements ConstString in several core places in the library, improving performance.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-02-27 18:23:23 +01:00
parent 1d3a8da99e
commit 412e0a4d63
17 changed files with 161 additions and 148 deletions

View File

@@ -2,30 +2,25 @@
#include <algorithm>
#include "../../Core/Exceptions/CreatureException.hpp"
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const std::string& growthRate,
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const Arbutils::CaseInsensitiveConstString& growthRate,
uint32_t experience) const {
auto g = growthRate;
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
auto find = _growthRates.find(g);
auto find = _growthRates.find(growthRate);
if (find == _growthRates.end()) {
throw CreatureException("Invalid growth rate was requested.");
}
return find->second->CalculateLevel(experience);
}
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const std::string& growthRate,
uint8_t level) const {
auto g = growthRate;
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
auto find = _growthRates.find(g);
uint32_t
CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const Arbutils::CaseInsensitiveConstString& growthRate,
uint8_t level) const {
auto find = _growthRates.find(growthRate);
if (find == _growthRates.end()) {
throw CreatureException("Invalid growth rate was requested.");
}
return find->second->CalculateExperience(level);
}
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const std::string& name,
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const Arbutils::CaseInsensitiveConstString& name,
CreatureLib::Library::GrowthRate* rate) {
auto g = name;
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
_growthRates.insert({g, rate});
_growthRates.insert({name, rate});
}