diff options
author | Christopher L. Conway <christopherleeconway@gmail.com> | 2010-02-23 17:15:44 +0000 |
---|---|---|
committer | Christopher L. Conway <christopherleeconway@gmail.com> | 2010-02-23 17:15:44 +0000 |
commit | 4c1cb16059e6e484581873dfb3103851183ccc72 (patch) | |
tree | 692ccbf8b07aef6ca8b8adc96a5de50cc408d0b1 /src/parser/symbol_table.h | |
parent | 7115bef6bc8aac38b5e718db8fcb39c26ef4954a (diff) |
Minor optimizations to parser (use const string& for ids, keep only one binding in symtab)
Diffstat (limited to 'src/parser/symbol_table.h')
-rw-r--r-- | src/parser/symbol_table.h | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/parser/symbol_table.h b/src/parser/symbol_table.h index dd110c4c1..1f43dbda6 100644 --- a/src/parser/symbol_table.h +++ b/src/parser/symbol_table.h @@ -42,8 +42,12 @@ class SymbolTable { private: /** The name to expression bindings */ + typedef __gnu_cxx::hash_map<std::string, ObjectType> + LookupTable; +/* typedef __gnu_cxx::hash_map<std::string, std::stack<ObjectType> > LookupTable; +*/ /** The table iterator */ typedef typename LookupTable::iterator table_iterator; /** The table iterator */ @@ -58,21 +62,23 @@ public: * Bind the name of the variable to the given expression. If the variable * has been bind before, this will redefine it until its undefined. */ - void bindName(const std::string name, const ObjectType& obj) throw () { - d_nameBindings[name].push(obj); + void bindName(const std::string& name, const ObjectType& obj) throw () { + d_nameBindings[name] = obj; Assert(isBound(name), "Expected name to be bound!"); } /** * Unbinds the last binding of the name to the expression. */ - void unbindName(const std::string name) throw () { + void unbindName(const std::string& name) throw () { table_iterator find = d_nameBindings.find(name); if(find != d_nameBindings.end()) { +/* find->second.pop(); if(find->second.empty()) { +*/ d_nameBindings.erase(find); - } +/* }*/ } } @@ -80,16 +86,16 @@ public: * Returns the last binding expression of the name. * Requires the name to have a binding in the table. */ - ObjectType getObject(const std::string name) throw () { + ObjectType getObject(const std::string& name) throw () { table_iterator find = d_nameBindings.find(name); Assert(find != d_nameBindings.end()); - return find->second.top(); + return find->second /*.top()*/ ; } /** * Returns true is name is bound to an expression. */ - bool isBound(const std::string name) const throw () { + bool isBound(const std::string& name) const throw () { const_table_iterator find = d_nameBindings.find(name); return (find != d_nameBindings.end()); } |