Avoid unnecessary dynamic cast in symbol equality function

This commit is contained in:
Max Brunsfeld 2014-04-23 13:12:33 -07:00
parent 2b883a72a2
commit 020614824a
2 changed files with 7 additions and 2 deletions

View file

@ -17,9 +17,13 @@ namespace tree_sitter {
index(index),
options(options) {}
bool ISymbol::operator==(const ISymbol &other) const {
return (other.index == index) && (other.options == options);
}
bool ISymbol::operator==(const Rule &rule) const {
const ISymbol *other = dynamic_cast<const ISymbol *>(&rule);
return other && (other->index == index) && (other->options == options);
return other && this->operator==(*other);
}
size_t ISymbol::hash_code() const {

View file

@ -15,7 +15,8 @@ namespace tree_sitter {
explicit ISymbol(int index);
ISymbol(int index, SymbolOption options);
bool operator==(const Rule& other) const;
bool operator==(const ISymbol &other) const;
bool operator==(const Rule &other) const;
size_t hash_code() const;
rule_ptr copy() const;