From 020614824a26d2ecf3819d6005dcd9f70ec3ccff Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 23 Apr 2014 13:12:33 -0700 Subject: [PATCH] Avoid unnecessary dynamic cast in symbol equality function --- src/compiler/rules/interned_symbol.cc | 6 +++++- src/compiler/rules/interned_symbol.h | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/rules/interned_symbol.cc b/src/compiler/rules/interned_symbol.cc index 6c366241..d7007229 100644 --- a/src/compiler/rules/interned_symbol.cc +++ b/src/compiler/rules/interned_symbol.cc @@ -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(&rule); - return other && (other->index == index) && (other->options == options); + return other && this->operator==(*other); } size_t ISymbol::hash_code() const { diff --git a/src/compiler/rules/interned_symbol.h b/src/compiler/rules/interned_symbol.h index e1b574ba..6028fbeb 100644 --- a/src/compiler/rules/interned_symbol.h +++ b/src/compiler/rules/interned_symbol.h @@ -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;