summaryrefslogtreecommitdiff
path: root/src/scope.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-24 04:14:34 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-24 04:14:34 -0500
commit11a217a481c87cc812a9deb0000d65ecce8e2ba2 (patch)
treeb6a92a6c08a8fa2208b8bf95d97a5d75ba67db0a /src/scope.cc
parent5cd8e5965294babfce4ed3eed7d8461c1649fe5a (diff)
downloadfork-ledger-11a217a481c87cc812a9deb0000d65ecce8e2ba2.tar.gz
fork-ledger-11a217a481c87cc812a9deb0000d65ecce8e2ba2.tar.bz2
fork-ledger-11a217a481c87cc812a9deb0000d65ecce8e2ba2.zip
Very minor but easy optimization for symbol_scope_t
Lots of symbol_scope_t throwaway objects get created during value expression calculation, and 99% of them are never used. Therefore, the std::map which each contains is now within an optional<> wrapper, so that no constructor happens unless one is actually used.
Diffstat (limited to 'src/scope.cc')
-rw-r--r--src/scope.cc24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/scope.cc b/src/scope.cc
index 99f6b669..64736ca3 100644
--- a/src/scope.cc
+++ b/src/scope.cc
@@ -42,15 +42,18 @@ void symbol_scope_t::define(const symbol_t::kind_t kind,
{
DEBUG("scope.symbols", "Defining '" << name << "' = " << def);
+ if (! symbols)
+ symbols = symbol_map();
+
std::pair<symbol_map::iterator, bool> result
- = symbols.insert(symbol_map::value_type(symbol_t(kind, name, def), def));
+ = symbols->insert(symbol_map::value_type(symbol_t(kind, name, def), def));
if (! result.second) {
- symbol_map::iterator i = symbols.find(symbol_t(kind, name));
- assert(i != symbols.end());
- symbols.erase(i);
+ symbol_map::iterator i = symbols->find(symbol_t(kind, name));
+ assert(i != symbols->end());
+ symbols->erase(i);
- result = symbols.insert(symbol_map::value_type(symbol_t(kind, name, def),
- def));
+ result = symbols->insert(symbol_map::value_type(symbol_t(kind, name, def),
+ def));
if (! result.second)
throw_(compile_error,
_("Redefinition of '%1' in the same scope") << name);
@@ -60,10 +63,11 @@ void symbol_scope_t::define(const symbol_t::kind_t kind,
expr_t::ptr_op_t symbol_scope_t::lookup(const symbol_t::kind_t kind,
const string& name)
{
- symbol_map::const_iterator i = symbols.find(symbol_t(kind, name));
- if (i != symbols.end())
- return (*i).second;
-
+ if (symbols) {
+ symbol_map::const_iterator i = symbols->find(symbol_t(kind, name));
+ if (i != symbols->end())
+ return (*i).second;
+ }
return child_scope_t::lookup(kind, name);
}