2
0
Эх сурвалжийг харах

Refactor sq_call to get rid of dead code.

After doing a `return SQ_ERROR;` in the else branch the following code is never reached. So the function either returns SQ_ERROR on failure to invoke the closure or SQ_OK in all other cases. Same behavior different code.
Sandu Liviu Catalin 7 жил өмнө
parent
commit
969ca8ee70
1 өөрчлөгдсөн 6 нэмэгдсэн , 14 устгасан
  1. 6 14
      squirrel/sqapi.cpp

+ 6 - 14
squirrel/sqapi.cpp

@@ -1175,23 +1175,15 @@ SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror)
 SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror)
 SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror)
 {
 {
     SQObjectPtr res;
     SQObjectPtr res;
-    if(v->Call(v->GetUp(-(params+1)),params,v->_top-params,res,raiseerror?true:false)){
-
-        if(!v->_suspended) {
-            v->Pop(params);//pop args
-        }
-        if(retval){
-            v->Push(res);
-        }
-        return SQ_OK;
-    }
-    else {
-        v->Pop(params);
+    if(!v->Call(v->GetUp(-(params+1)),params,v->_top-params,res,raiseerror?true:false)){
+        v->Pop(params); //pop args
         return SQ_ERROR;
         return SQ_ERROR;
     }
     }
     if(!v->_suspended)
     if(!v->_suspended)
-        v->Pop(params);
-    return sq_throwerror(v,_SC("call failed"));
+        v->Pop(params); //pop args
+    if(retval)
+        v->Push(res); // push result
+    return SQ_OK;
 }
 }
 
 
 SQRESULT sq_tailcall(HSQUIRRELVM v, SQInteger nparams)
 SQRESULT sq_tailcall(HSQUIRRELVM v, SQInteger nparams)