Reduce dynamic memory allocation by reusing scope maps in symbol table.

This commit is contained in:
Matt Pharr
2012-05-04 12:45:22 -07:00
parent 78d62705cc
commit e495ef2c48
2 changed files with 13 additions and 2 deletions

13
sym.cpp
View File

@@ -73,14 +73,23 @@ SymbolTable::~SymbolTable() {
void
SymbolTable::PushScope() {
variables.push_back(new SymbolMapType);
SymbolMapType *sm;
if (freeSymbolMaps.size() > 0) {
sm = freeSymbolMaps.back();
freeSymbolMaps.pop_back();
sm->erase(sm->begin(), sm->end());
}
else
sm = new SymbolMapType;
variables.push_back(sm);
}
void
SymbolTable::PopScope() {
Assert(variables.size() > 1);
delete variables.back();
freeSymbolMaps.push_back(variables.back());
variables.pop_back();
}