Implements ConstString in several core places in the library, improving performance.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,21 +2,19 @@
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
std::string growthRate, uint8_t captureRate)
|
||||
: _id(id), _genderRate(genderRatio), _growthRate(std::move(growthRate)), _captureRate(captureRate),
|
||||
_variants({{"default", defaultVariant}}), _name(std::move(name)) {}
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name,
|
||||
const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate)
|
||||
: _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
|
||||
_variants({{"default"_cnc, defaultVariant}}), _name(name) {}
|
||||
|
||||
bool CreatureSpecies::HasVariant(const std::string& name) const {
|
||||
auto key = name;
|
||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||
return _variants.find(key) != _variants.end();
|
||||
bool CreatureSpecies::HasVariant(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return _variants.find(name) != _variants.end();
|
||||
}
|
||||
|
||||
bool CreatureSpecies::TryGetVariant(const std::string& name, const SpeciesVariant*& out) const {
|
||||
auto key = name;
|
||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||
auto find = _variants.find(key);
|
||||
bool CreatureSpecies::TryGetVariant(const Arbutils::CaseInsensitiveConstString& name,
|
||||
const SpeciesVariant*& out) const {
|
||||
auto find = _variants.find(name);
|
||||
if (find != _variants.end()) {
|
||||
out = find->second;
|
||||
return true;
|
||||
@@ -24,20 +22,17 @@ bool CreatureSpecies::TryGetVariant(const std::string& name, const SpeciesVarian
|
||||
return false;
|
||||
}
|
||||
|
||||
const SpeciesVariant* CreatureSpecies::GetVariant(const std::string& name) const {
|
||||
const SpeciesVariant* CreatureSpecies::GetVariant(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
auto key = name;
|
||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||
return _variants.at(key);
|
||||
}
|
||||
|
||||
void CreatureSpecies::SetVariant(const std::string& name, const SpeciesVariant* variant) {
|
||||
auto key = name;
|
||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||
auto find = _variants.find(key);
|
||||
void CreatureSpecies::SetVariant(const Arbutils::CaseInsensitiveConstString& name, const SpeciesVariant* variant) {
|
||||
auto find = _variants.find(name);
|
||||
if (find != _variants.end()) {
|
||||
delete find->second;
|
||||
}
|
||||
_variants[key] = variant;
|
||||
_variants[name] = variant;
|
||||
}
|
||||
|
||||
Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const {
|
||||
@@ -46,6 +41,4 @@ Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const {
|
||||
if (val >= this->_genderRate)
|
||||
return Gender ::Female;
|
||||
return Gender ::Male;
|
||||
}
|
||||
|
||||
const std::string& CreatureSpecies::GetName() const { return _name; }
|
||||
}
|
||||
Reference in New Issue
Block a user