Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(42)

Unified Diff: lily/lily-lexer.cc

Issue 549920043: Use a hash table for the lexer keywords (Closed)
Patch Set: add missing header Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lily/keyword.cc ('k') | lily/lily-lexer-scheme.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lily/lily-lexer.cc
diff --git a/lily/lily-lexer.cc b/lily/lily-lexer.cc
index 4851349cd08f90d04c2f86211bfaa45ea43206f6..077167b1d1bd133eabd73a3f8359cc18df4051ea 100644
--- a/lily/lily-lexer.cc
+++ b/lily/lily-lexer.cc
@@ -19,13 +19,9 @@
#include "lily-lexer.hh"
-#include <cctype>
-#include <sstream>
-
#include "context.hh" // for nested_property_alist
#include "international.hh"
#include "interval.hh"
-#include "keyword.hh"
#include "main.hh"
#include "moment.hh"
#include "parser.hh"
@@ -36,11 +32,13 @@
#include "lily-parser.hh"
#include "ly-module.hh"
+#include <cctype>
+#include <sstream>
+#include <unordered_map>
+
using std::string;
-static Keyword_ent the_key_tab[]
-=
-{
+static std::unordered_map<std::string, int> keytable{
{"accepts", ACCEPTS},
{"addlyrics", ADDLYRICS},
{"alias", ALIAS},
@@ -86,13 +84,12 @@ static Keyword_ent the_key_tab[]
{"type", TYPE},
{"unset", UNSET},
{"with", WITH},
- {0, 0}
};
Lily_lexer::Lily_lexer (Sources *sources, Lily_parser *parser)
{
parser_ = parser;
- keytable_ = new Keyword_table (the_key_tab);
+
chordmodifier_tab_ = SCM_EOL;
pitchname_tab_stack_ = SCM_EOL;
sources_ = sources;
@@ -114,7 +111,6 @@ Lily_lexer::Lily_lexer (Lily_lexer const &src, Lily_parser *parser,
: Includable_lexer ()
{
parser_ = parser;
- keytable_ = (src.keytable_) ? new Keyword_table (*src.keytable_) : 0;
chordmodifier_tab_ = src.chordmodifier_tab_;
pitchname_tab_stack_ = src.pitchname_tab_stack_;
sources_ = src.sources_;
@@ -134,11 +130,6 @@ Lily_lexer::Lily_lexer (Lily_lexer const &src, Lily_parser *parser,
push_note_state (SCM_EOL);
}
-Lily_lexer::~Lily_lexer ()
-{
- delete keytable_;
-}
-
void
Lily_lexer::add_scope (SCM module)
{
@@ -183,27 +174,12 @@ Lily_lexer::set_current_scope ()
int
Lily_lexer::lookup_keyword (const string &s)
{
- return keytable_->lookup (s.c_str ());
-}
-
-SCM
-Lily_lexer::keyword_list () const
-{
- if (!keytable_)
- return SCM_EOL;
-
- SCM l = SCM_EOL;
- SCM *tail = &l;
- for (vsize i = 0; i < keytable_->table_.size (); i++)
+ auto const &it = keytable.find (s);
+ if (it == keytable.end ())
{
- *tail = scm_acons (scm_from_utf8_string (keytable_->table_[i].name_),
- scm_from_int (keytable_->table_[i].tokcode_),
- SCM_EOL);
-
- tail = SCM_CDRLOC (*tail);
+ return -1;
}
-
- return l;
+ return it->second;
}
SCM
« no previous file with comments | « lily/keyword.cc ('k') | lily/lily-lexer-scheme.cc » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b