some simple optimiziations

This commit is contained in:
Eliot Horowitz
2009-11-04 14:48:36 -05:00
parent bdbd9143ed
commit 01c85879b1
2 changed files with 12 additions and 9 deletions

View File

@@ -761,17 +761,19 @@ namespace mongo {
JSBool native_helper( JSContext *cx , JSObject *obj , uintN argc, jsval *argv , jsval *rval ){
Convertor c(cx);
uassert( "native_helper needs at least 1 arg" , argc >= 1 );
NativeFunction func = (NativeFunction)((long long)c.toNumber( argv[0] ));
NativeFunction func = (NativeFunction)((long long)c.getNumber( obj , "x" ) );
assert( func );
BSONObjBuilder args;
for ( uintN i=1; i<argc; i++ ){
c.append( args , args.numStr( i ) , argv[i] );
BSONObj a;
if ( argc > 0 ){
BSONObjBuilder args;
for ( uintN i=0; i<argc; i++ ){
c.append( args , args.numStr( i ) , argv[i] );
}
a = args.obj();
}
BSONObj a = args.obj();
BSONObj out = func( a );
if ( out.isEmpty() ){
@@ -1299,7 +1301,8 @@ namespace mongo {
_convertor->setProperty( _global , (name + "_").c_str() , _convertor->toval( (double)(long long)func ) );
stringstream code;
code << field << " = function(){ var a = [ " << field << "_ ]; for ( var i=0; i<arguments.length; i++ ){ a.push( arguments[i] ); } return nativeHelper.apply( null , a ); }";
code << field << "_" << " = { x : " << field << "_ }; ";
code << field << " = function(){ return nativeHelper.apply( " << field << "_ , arguments ); }";
exec( code.str().c_str() );
}