Skip to content
This repository
Browse code

[Perf] Dont duplicate the function lookup in fb_call_user_func_safe*

Summary: fb_call_user_func_safe etc were implemented via is_callable, then
call_user_func_array. Instead, we can do a single lookup of the CallInfo.

Test Plan: fast_tests slow_tests

Reviewers: myang, qigao

Reviewed By: myang

CC: ps, mwilliams, myang

Differential Revision: 343223
  • Loading branch information...
commit 7f8439ad22bb18bcf9468aa028b90993c7b06a85 1 parent d8d89af
markw65 authored October 12, 2011 scottmac committed October 17, 2011
19  src/runtime/base/builtin_functions.cpp
@@ -312,6 +312,25 @@ bool get_user_func_handler(CVarRef function, bool skip,
312 312
   return false;
313 313
 }
314 314
 
  315
+bool get_callable_user_func_handler(CVarRef function,
  316
+                                    MethodCallPackage &mcp,
  317
+                                    String &classname, String &methodname,
  318
+                                    bool &doBind) {
  319
+  bool ret = get_user_func_handler(function, true, mcp,
  320
+                                   classname, methodname, doBind, false);
  321
+  if (ret && mcp.ci->m_flags & (CallInfo::Protected|CallInfo::Private)) {
  322
+    classname = mcp.getClassName();
  323
+    if (!ClassInfo::HasAccess(classname, *mcp.name,
  324
+                              mcp.ci->m_flags & CallInfo::StaticMethod ||
  325
+                              !mcp.obj,
  326
+                              mcp.obj)) {
  327
+      ret = false;
  328
+    }
  329
+  }
  330
+
  331
+  return ret;
  332
+}
  333
+
315 334
 Variant f_call_user_func_array(CVarRef function, CArrRef params,
316 335
                                bool bound /* = false */) {
317 336
   MethodCallPackage mcp;
4  src/runtime/base/builtin_functions.h
@@ -339,6 +339,10 @@ bool get_user_func_handler(CVarRef function, bool skip,
339 339
                            MethodCallPackage& mcp,
340 340
                            String &classname, String &methodname,
341 341
                            bool &doBind, bool warn = true);
  342
+bool get_callable_user_func_handler(CVarRef function,
  343
+                                    MethodCallPackage& mcp,
  344
+                                    String &classname, String &methodname,
  345
+                                    bool &doBind);
342 346
 
343 347
 Variant invoke_func_few_handler(void *extra, CArrRef params,
344 348
                                 Variant (*few_args)(
39  src/runtime/ext/ext_fb.cpp
@@ -839,20 +839,43 @@ Array f_fb_call_user_func_safe(int _argc, CVarRef function,
839 839
   return f_fb_call_user_func_array_safe(function, _argv);
840 840
 }
841 841
 
  842
+static Variant fb_call_user_func_safe(CVarRef function, CArrRef params,
  843
+                                      bool &ok) {
  844
+  MethodCallPackage mcp;
  845
+  String classname, methodname;
  846
+  bool doBind;
  847
+  if (get_callable_user_func_handler(function,
  848
+                                     mcp, classname, methodname, doBind)) {
  849
+    ok = true;
  850
+    if (doBind) {
  851
+      FrameInjection::StaticClassNameHelper scn(
  852
+        ThreadInfo::s_threadInfo.getNoCheck(), classname);
  853
+      ASSERT(!mcp.m_isFunc);
  854
+      return mcp.ci->getMeth()(mcp, params);
  855
+    } else {
  856
+      if (mcp.m_isFunc) {
  857
+        return mcp.ci->getFunc()(mcp.extra, params);
  858
+      } else {
  859
+        return mcp.ci->getMeth()(mcp, params);
  860
+      }
  861
+    }
  862
+  }
  863
+  ok = false;
  864
+  return null;
  865
+}
  866
+
842 867
 Variant f_fb_call_user_func_safe_return(int _argc, CVarRef function,
843 868
                                         CVarRef def,
844 869
                                         CArrRef _argv /* = null_array */) {
845  
-  if (f_is_callable(function)) {
846  
-    return f_call_user_func_array(function, _argv);
847  
-  }
848  
-  return def;
  870
+  bool ok;
  871
+  Variant ret = fb_call_user_func_safe(function, _argv, ok);
  872
+  return ok ? ret : def;
849 873
 }
850 874
 
851 875
 Array f_fb_call_user_func_array_safe(CVarRef function, CArrRef params) {
852  
-  if (f_is_callable(function)) {
853  
-    return CREATE_VECTOR2(true, f_call_user_func_array(function, params));
854  
-  }
855  
-  return CREATE_VECTOR2(false, null);
  876
+  bool ok;
  877
+  Variant ret = fb_call_user_func_safe(function, params, ok);
  878
+  return CREATE_VECTOR2(ok, ret);
856 879
 }
857 880
 
858 881
 ///////////////////////////////////////////////////////////////////////////////
2  src/runtime/ext/ext_function.cpp
@@ -53,7 +53,7 @@ bool f_is_callable(CVarRef v, bool syntax /* = false */,
53 53
     String classname, methodname;
54 54
     bool doBind;
55 55
     ret = get_user_func_handler(v, true, mcp,
56  
-                                     classname, methodname, doBind, false);
  56
+                                classname, methodname, doBind, false);
57 57
     if (ret && mcp.ci->m_flags & (CallInfo::Protected|CallInfo::Private)) {
58 58
       classname = mcp.getClassName();
59 59
       if (!ClassInfo::HasAccess(classname, *mcp.name,

0 notes on commit 7f8439a

Please sign in to comment.
Something went wrong with that request. Please try again.