[svn:parrot] r48714 - trunk/src

chromatic at svn.parrot.org chromatic at svn.parrot.org
Sun Aug 29 00:52:48 UTC 2010


Author: chromatic
Date: Sun Aug 29 00:52:48 2010
New Revision: 48714
URL: https://trac.parrot.org/parrot/changeset/48714

Log:
[OO] Removed unused code from find_method_direct().

This allows the coalescing of find_method_direct_1() into find_method_direct(),
which saves a tiny bit of overhead.

Modified:
   trunk/src/oo.c

Modified: trunk/src/oo.c
==============================================================================
--- trunk/src/oo.c	Sun Aug 29 00:52:45 2010	(r48713)
+++ trunk/src/oo.c	Sun Aug 29 00:52:48 2010	(r48714)
@@ -50,15 +50,6 @@
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);
 
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-static PMC * find_method_direct_1(PARROT_INTERP,
-    ARGIN(PMC *_class),
-    ARGIN(STRING *method_name))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        __attribute__nonnull__(3);
-
 PARROT_INLINE
 PARROT_CANNOT_RETURN_NULL
 PARROT_WARN_UNUSED_RESULT
@@ -81,10 +72,6 @@
 #define ASSERT_ARGS_fail_if_type_exists __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(name))
-#define ASSERT_ARGS_find_method_direct_1 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(interp) \
-    , PARROT_ASSERT_ARG(_class) \
-    , PARROT_ASSERT_ARG(method_name))
 #define ASSERT_ARGS_get_pmc_proxy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_invalidate_all_caches __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -94,6 +81,63 @@
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: static */
 
+
+/*
+
+=item C<static void debug_trace_find_meth(PARROT_INTERP, const PMC *_class,
+const STRING *name, const PMC *sub)>
+
+Print some information about the search for a sub.
+
+=cut
+
+*/
+
+#ifdef NDEBUG
+#  define TRACE_FM(i, c, m, sub)
+#else
+#  define TRACE_FM(i, c, m, sub) \
+    debug_trace_find_meth((i), (c), (m), (sub))
+
+static void
+debug_trace_find_meth(PARROT_INTERP, ARGIN(const PMC *_class),
+        ARGIN(const STRING *name), ARGIN_NULLOK(const PMC *sub))
+{
+    ASSERT_ARGS(debug_trace_find_meth)
+    STRING *class_name;
+    const char *result;
+    Interp *tracer;
+
+    if (!Interp_trace_TEST(interp, PARROT_TRACE_FIND_METH_FLAG))
+        return;
+
+    if (PObj_is_class_TEST(_class)) {
+        SLOTTYPE * const class_array    = PMC_data_typed(_class, SLOTTYPE *);
+        PMC      * const class_name_pmc = get_attrib_num(class_array, PCD_CLASS_NAME);
+        class_name                      = VTABLE_get_string(interp, class_name_pmc);
+    }
+    else
+        class_name = _class->vtable->whoami;
+
+    if (sub) {
+        if (sub->vtable->base_type == enum_class_NCI)
+            result = "NCI";
+        else
+            result = "Sub";
+    }
+    else
+        result = "no";
+
+    tracer = (interp->pdb && interp->pdb->debugger) ?
+        interp->pdb->debugger :
+        interp;
+    Parrot_io_eprintf(tracer, "# find_method class '%Ss' method '%Ss': %s\n",
+            class_name, name, result);
+}
+
+#endif
+
+
 /*
 
 =item C<void Parrot_oo_extract_methods_from_namespace(PARROT_INTERP, PMC *self,
@@ -870,15 +914,38 @@
 Parrot_find_method_direct(PARROT_INTERP, ARGIN(PMC *_class), ARGIN(STRING *method_name))
 {
     ASSERT_ARGS(Parrot_find_method_direct)
-    PMC * const found = find_method_direct_1(interp, _class, method_name);
 
-    if (!PMC_IS_NULL(found))
-        return found;
+    STRING * const class_str   = CONST_STRING(interp, "class");
+    STRING * const methods_str = CONST_STRING(interp, "methods");
+    PMC    * const mro         = _class->vtable->mro;
+    const INTVAL   n           = VTABLE_elements(interp, mro);
+    INTVAL         i;
+
+    for (i = 0; i < n; ++i) {
+        PMC * const _class    = VTABLE_get_pmc_keyed_int(interp, mro, i);
+        PMC * const ns        = VTABLE_get_namespace(interp, _class);
+        PMC * const class_obj = VTABLE_inspect_str(interp, ns, class_str);
+        PMC        *method    = PMCNULL;
+        PMC        *method_hash;
+
+        if (PMC_IS_NULL(class_obj))
+            method_hash = VTABLE_inspect_str(interp, ns, methods_str);
+        else
+            method_hash = VTABLE_inspect_str(interp, class_obj, methods_str);
+
+        if (!PMC_IS_NULL(method_hash))
+            method = VTABLE_get_pmc_keyed_str(interp, method_hash, method_name);
 
+        if (PMC_IS_NULL(method))
+            method = VTABLE_get_pmc_keyed_str(interp, ns, method_name);
 
-    if (Parrot_str_equal(interp, method_name, CONST_STRING(interp, "__get_string")))
-        return find_method_direct_1(interp, _class, CONST_STRING(interp, "__get_repr"));
+        TRACE_FM(interp, _class, method_name, method);
 
+        if (!PMC_IS_NULL(method))
+            return method;
+    }
+
+    TRACE_FM(interp, _class, method_name, NULL);
     return PMCNULL;
 }
 
@@ -963,116 +1030,6 @@
 
 /*
 
-=item C<static void debug_trace_find_meth(PARROT_INTERP, const PMC *_class,
-const STRING *name, const PMC *sub)>
-
-Print some information about the search for a sub.
-
-=cut
-
-*/
-
-#ifdef NDEBUG
-#  define TRACE_FM(i, c, m, sub)
-#else
-#  define TRACE_FM(i, c, m, sub) \
-    debug_trace_find_meth((i), (c), (m), (sub))
-
-static void
-debug_trace_find_meth(PARROT_INTERP, ARGIN(const PMC *_class),
-        ARGIN(const STRING *name), ARGIN_NULLOK(const PMC *sub))
-{
-    ASSERT_ARGS(debug_trace_find_meth)
-    STRING *class_name;
-    const char *result;
-    Interp *tracer;
-
-    if (!Interp_trace_TEST(interp, PARROT_TRACE_FIND_METH_FLAG))
-        return;
-
-    if (PObj_is_class_TEST(_class)) {
-        SLOTTYPE * const class_array    = PMC_data_typed(_class, SLOTTYPE *);
-        PMC      * const class_name_pmc = get_attrib_num(class_array, PCD_CLASS_NAME);
-        class_name                      = VTABLE_get_string(interp, class_name_pmc);
-    }
-    else
-        class_name = _class->vtable->whoami;
-
-    if (sub) {
-        if (sub->vtable->base_type == enum_class_NCI)
-            result = "NCI";
-        else
-            result = "Sub";
-    }
-    else
-        result = "no";
-
-    tracer = (interp->pdb && interp->pdb->debugger) ?
-        interp->pdb->debugger :
-        interp;
-    Parrot_io_eprintf(tracer, "# find_method class '%Ss' method '%Ss': %s\n",
-            class_name, name, result);
-}
-
-#endif
-
-
-/*
-
-=item C<static PMC * find_method_direct_1(PARROT_INTERP, PMC *_class, STRING
-*method_name)>
-
-Find the method with the given name in the specified class.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-static PMC *
-find_method_direct_1(PARROT_INTERP, ARGIN(PMC *_class),
-                              ARGIN(STRING *method_name))
-{
-    ASSERT_ARGS(find_method_direct_1)
-    INTVAL i;
-
-    PMC * const  mro = _class->vtable->mro;
-    const INTVAL n   = VTABLE_elements(interp, mro);
-    STRING * const methods_str = CONST_STRING(interp, "methods");
-    STRING * const class_str = CONST_STRING(interp, "class");
-
-    for (i = 0; i < n; ++i) {
-        PMC * const _class    = VTABLE_get_pmc_keyed_int(interp, mro, i);
-        PMC * const ns        = VTABLE_get_namespace(interp, _class);
-        PMC * const class_obj = VTABLE_inspect_str(interp, ns, class_str);
-        PMC           *method = PMCNULL;
-        PMC * method_hash;
-
-        if (PMC_IS_NULL(class_obj))
-            method_hash = VTABLE_inspect_str(interp, ns, methods_str);
-        else
-            method_hash = VTABLE_inspect_str(interp, class_obj, methods_str);
-
-        if (!PMC_IS_NULL(method_hash))
-            method = VTABLE_get_pmc_keyed_str(interp, method_hash, method_name);
-
-        if (PMC_IS_NULL(method))
-            method = VTABLE_get_pmc_keyed_str(interp, ns, method_name);
-
-        TRACE_FM(interp, _class, method_name, method);
-
-        if (!PMC_IS_NULL(method))
-            return method;
-    }
-
-    TRACE_FM(interp, _class, method_name, NULL);
-    return PMCNULL;
-}
-
-
-/*
-
 =item C<static PMC* C3_merge(PARROT_INTERP, PMC *merge_list)>
 
 Merge together the MRO of the items in the list.


More information about the parrot-commits mailing list