Simplify CFCBindMeth_method_def

Remove unneeded static functions.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/821bf0d0
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/821bf0d0
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/821bf0d0

Branch: refs/heads/master
Commit: 821bf0d0b8c31609ebbc54949f8262ef38393e3a
Parents: 8fbf9c9
Author: Nick Wellnhofer <wellnho...@aevum.de>
Authored: Tue Feb 28 16:41:14 2017 +0100
Committer: Nick Wellnhofer <wellnho...@aevum.de>
Committed: Thu Mar 2 20:08:05 2017 +0100

----------------------------------------------------------------------
 compiler/src/CFCBindMethod.c | 50 +++++++++++----------------------------
 1 file changed, 14 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/821bf0d0/compiler/src/CFCBindMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindMethod.c b/compiler/src/CFCBindMethod.c
index e6880b4..fad6fd5 100644
--- a/compiler/src/CFCBindMethod.c
+++ b/compiler/src/CFCBindMethod.c
@@ -32,44 +32,8 @@
   #define false 0
 #endif
 
-static char*
-S_method_def(CFCMethod *method, CFCClass *klass, int optimized_final_meth);
-
-/* Create a method invocation routine that resolves to a function name
- * directly, since this method may not be overridden.
- */
-static char*
-S_optimized_final_method_def(CFCMethod *method, CFCClass *klass) {
-    return S_method_def(method, klass, true);
-}
-
-/* Create a method invocation routine which uses vtable dispatch.
- */
-static char*
-S_virtual_method_def(CFCMethod *method, CFCClass *klass) {
-    return S_method_def(method, klass, false);
-}
-
 char*
 CFCBindMeth_method_def(CFCMethod *method, CFCClass *klass) {
-    // If the method is final and the class where it is declared final is in
-    // the same parcel as the invocant, we can optimize the call by resolving
-    // to the implementing function directly.
-    if (CFCMethod_final(method)) {
-        CFCClass *ancestor = klass;
-        while (ancestor && !CFCMethod_is_fresh(method, ancestor)) {
-            ancestor = CFCClass_get_parent(ancestor);
-        }
-        if (CFCClass_get_parcel(ancestor) == CFCClass_get_parcel(klass)) {
-            return S_optimized_final_method_def(method, klass);
-        }
-    }
-
-    return S_virtual_method_def(method, klass);
-}
-
-static char*
-S_method_def(CFCMethod *method, CFCClass *klass, int optimized_final_meth) {
     CFCParamList *param_list = CFCMethod_get_param_list(method);
     const char *PREFIX         = CFCClass_get_PREFIX(klass);
     const char *invoker_struct = CFCClass_full_struct_sym(klass);
@@ -95,6 +59,20 @@ S_method_def(CFCMethod *method, CFCClass *klass, int 
optimized_final_meth) {
     const char *ret_type_str = CFCType_to_c(return_type);
     const char *maybe_return = CFCType_is_void(return_type) ? "" : "return ";
 
+    // If the method is final and the class where it is declared final is in
+    // the same parcel as the invocant, we can optimize the call by resolving
+    // to the implementing function directly.
+    int optimized_final_meth = false;
+    if (CFCMethod_final(method)) {
+        CFCClass *ancestor = klass;
+        while (ancestor && !CFCMethod_is_fresh(method, ancestor)) {
+            ancestor = CFCClass_get_parent(ancestor);
+        }
+        if (CFCClass_in_same_parcel(ancestor, klass)) {
+            optimized_final_meth = true;
+        }
+    }
+
     const char innards_pattern[] =
         "    const %s method = (%s)cfish_obj_method(%s, %s);\n"
         "    %smethod(%s);\n"

Reply via email to