changed Subtypes map into a vector, hoping for some speed improvements.
This commit is contained in:
@@ -29,6 +29,9 @@ Subtypes::Subtypes()
|
||||
|
||||
int Subtypes::find(string value, bool forceAdd)
|
||||
{
|
||||
if (!value.size())
|
||||
return 0;
|
||||
|
||||
if (value[0] >= 97 && value[0] <= 122) value[0] -= 32; //Poor man's camelcase. We assume strings we get are either Camelcased or lowercase
|
||||
map<string, int>::iterator it = values.find(value);
|
||||
if (it != values.end()) return it->second;
|
||||
@@ -42,11 +45,15 @@ int Subtypes::find(string value, bool forceAdd)
|
||||
// Adds a subtype to the list, and associated it with a parent type.
|
||||
//The association can happen only once, a subtype is then definitely associated to its parent type.
|
||||
// If you associate "goblin" to "creature", trying to associate "goblin" to "land" afterwards will fail. "goblin" will stay associated to its first parent.
|
||||
int Subtypes::add(string value, int parentType)
|
||||
int Subtypes::add(string value, unsigned int parentType)
|
||||
{
|
||||
int subtype = find(value);
|
||||
if (parentType && isSubType(subtype) && !subtypesToType[subtype])
|
||||
unsigned int subtype = find(value);
|
||||
if (parentType && isSubType(subtype))
|
||||
{
|
||||
if ((unsigned int)(subtypesToType.size()) < subtype + 1)
|
||||
subtypesToType.resize(1 + subtype * 2, 0); //multiplying by 2 to avoid resizing at every insertion
|
||||
subtypesToType[subtype] = parentType;
|
||||
}
|
||||
return subtype;
|
||||
}
|
||||
|
||||
@@ -62,26 +69,26 @@ bool Subtypes::isSubtypeOfType(string subtype, string type)
|
||||
unsigned int typeInt = find(type);
|
||||
return isSubtypeOfType(subtypeInt, typeInt);
|
||||
}
|
||||
bool Subtypes::isSubtypeOfType(int subtype, int type)
|
||||
bool Subtypes::isSubtypeOfType(unsigned int subtype, unsigned int type)
|
||||
{
|
||||
return (subtypesToType[subtype] == type);
|
||||
}
|
||||
|
||||
bool Subtypes::isSuperType(int type)
|
||||
bool Subtypes::isSuperType(unsigned int type)
|
||||
{
|
||||
return (type == TYPE_BASIC || type == TYPE_WORLD || type == TYPE_SNOW || type == TYPE_LEGENDARY);
|
||||
}
|
||||
|
||||
bool Subtypes::isType(int type)
|
||||
bool Subtypes::isType(unsigned int type)
|
||||
{
|
||||
return (
|
||||
type == TYPE_CREATURE ||
|
||||
type == TYPE_ENCHANTMENT ||
|
||||
type == TYPE_SORCERY ||
|
||||
type == TYPE_INSTANT ||
|
||||
type == TYPE_LAND ||
|
||||
type == TYPE_LAND ||
|
||||
type == TYPE_ARTIFACT ||
|
||||
type ==TYPE_PLANESWALKER ||
|
||||
type == TYPE_PLANESWALKER ||
|
||||
type == TYPE_TRIBAL ||
|
||||
type == TYPE_PLANE ||
|
||||
type == TYPE_SCHEME ||
|
||||
@@ -89,7 +96,7 @@ bool Subtypes::isType(int type)
|
||||
);
|
||||
}
|
||||
|
||||
bool Subtypes::isSubType(int type)
|
||||
bool Subtypes::isSubType(unsigned int type)
|
||||
{
|
||||
return (!isSuperType(type) && !isType(type));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user