[seed] Remove duplicated code, call function instead



commit 29462f933d6068fa45281fbc0b47719ef4983c30
Author: Gustavo Noronha Silva <gustavo noronha collabora com>
Date:   Thu Mar 14 17:38:09 2013 -0300

    Remove duplicated code, call function instead
    
    seed_closure_invoke was a copy of seed_closure_invoke_with_context
    with just 2 additional statements before and 1 after the same
    code. This is bad because fixes need to be applied to both, a great
    oportunity for code reuse.

 libseed/seed-closure.c |   16 +++-------------
 1 files changed, 3 insertions(+), 13 deletions(-)
---
diff --git a/libseed/seed-closure.c b/libseed/seed-closure.c
index d0503e5..bac1b9b 100644
--- a/libseed/seed-closure.c
+++ b/libseed/seed-closure.c
@@ -368,20 +368,13 @@ seed_closure_invoke (GClosure * closure, JSValueRef * args, guint argc,
                     JSValueRef * exception)
 {
   JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
-  JSValueRef *real_args = g_newa (JSValueRef, argc + 1);
   JSValueRef ret;
-  guint i;
 
   seed_prepare_global_context (ctx);
-  for (i = 0; i < argc; i++)
-    real_args[i] = args[i];
-  real_args[argc] =
-    ((SeedClosure *) closure)->user_data ? ((SeedClosure *) closure)->
-    user_data : JSValueMakeNull (ctx);
 
   ret =
-    JSObjectCallAsFunction (ctx, ((SeedClosure *) closure)->function, NULL,
-                           argc + 1, real_args, exception);
+    seed_closure_invoke_with_context (ctx, closure, args, argc, exception);
+
   JSGlobalContextRelease ((JSGlobalContextRef) ctx);
 
   return ret;
@@ -393,7 +386,6 @@ seed_closure_invoke_with_context (JSContextRef ctx, GClosure * closure,
                                  JSValueRef * exception)
 {
   JSValueRef *real_args = g_newa (JSValueRef, argc + 1);
-  JSValueRef ret;
   guint i;
 
   for (i = 0; i < argc; i++)
@@ -402,11 +394,9 @@ seed_closure_invoke_with_context (JSContextRef ctx, GClosure * closure,
     ((SeedClosure *) closure)->user_data ? ((SeedClosure *) closure)->
     user_data : JSValueMakeNull (ctx);
 
-  ret =
+  return
     JSObjectCallAsFunction (ctx, ((SeedClosure *) closure)->function, NULL,
                            argc + 1, real_args, exception);
-
-  return ret;
 }
 
 GClosure *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]