cache functions

This commit is contained in:
Eliot Horowitz
2009-10-09 11:32:41 -04:00
parent 1119ad03f2
commit 445c662ffc
3 changed files with 30 additions and 3 deletions

View File

@@ -9,10 +9,14 @@ namespace mongo {
long long Scope::_lastVersion = 1;
int Scope::_numScopes = 0;
Scope::Scope() : _localDBName("") , _loadedVersion(0){
_numScopes++;
}
Scope::~Scope(){
_numScopes--;
}
ScriptEngine::ScriptEngine(){
@@ -122,6 +126,15 @@ namespace mongo {
setElement( n.valuestr() , v );
}
}
ScriptingFunction Scope::createFunction( const char * code ){
map<string,ScriptingFunction>::iterator i = _cachedFunctions.find( code );
if ( i != _cachedFunctions.end() )
return i->second;
ScriptingFunction f = _createFunction( code );
_cachedFunctions[code] = f;
return f;
}
typedef map< string , list<Scope*> > PoolToScopes;
@@ -261,6 +274,10 @@ namespace mongo {
return _real->createFunction( code );
}
ScriptingFunction _createFunction( const char * code ){
return _real->createFunction( code );
}
/**
* @return 0 on success
*/