Skip to content

Commit

Permalink
Avoid creating temporary strings adding symbols to Grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Baker authored and cwbaker committed Jun 2, 2023
1 parent 6821f78 commit 93160d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/lalr/GrammarSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

using namespace lalr;

GrammarSymbol::GrammarSymbol( const std::string& lexeme )
GrammarSymbol::GrammarSymbol( const char* lexeme )
: lexeme_( lexeme )
, identifier_()
, symbol_type_( SYMBOL_NULL )
Expand Down Expand Up @@ -66,8 +66,9 @@ GrammarSymbol* GrammarSymbol::implicit_terminal() const
}


bool GrammarSymbol::matches( const std::string& lexeme, SymbolType symbol_type ) const
bool GrammarSymbol::matches( const char* lexeme, SymbolType symbol_type ) const
{
LALR_ASSERT( lexeme );
return lexeme_ == lexeme && symbol_type_ == symbol_type;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lalr/GrammarSymbol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GrammarSymbol
std::multimap<const GrammarSymbol*, GrammarProduction*> reachable_productions_by_first_symbol_; ///< The productions reachable by right-most derivation from this symbol by their first symbol.

public:
GrammarSymbol( const std::string& lexeme );
GrammarSymbol( const char* lexeme );

inline const std::string& lexeme() const;
inline const std::string& identifier() const;
Expand All @@ -51,7 +51,7 @@ class GrammarSymbol
inline const std::multimap<const GrammarSymbol*, GrammarProduction*>& reachable_productions_by_first_symbol() const;
std::multimap<const GrammarSymbol*, GrammarProduction*>::const_iterator find_reachable_productions( const GrammarSymbol& first_symbol ) const;
GrammarSymbol* implicit_terminal() const;
bool matches( const std::string& lexeme, SymbolType symbol_type ) const;
bool matches( const char* lexeme, SymbolType symbol_type ) const;

void set_lexeme( const std::string& lexeme );
void set_identifier( const std::string& identifier );
Expand Down

0 comments on commit 93160d6

Please sign in to comment.