aboutsummaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorDmitry Antipov2014-09-11 17:21:19 +0400
committerDmitry Antipov2014-09-11 17:21:19 +0400
commit1dd1218653be3425e7f53ea1cfcb0d14addfaa05 (patch)
treea91548f460ecb1aa05ac79dacbb3054853cb9e25 /src/eval.c
parent20d362538021e154095f4b64f1b3505d3912fffd (diff)
downloademacs-1dd1218653be3425e7f53ea1cfcb0d14addfaa05.tar.gz
emacs-1dd1218653be3425e7f53ea1cfcb0d14addfaa05.zip
Remove redundant GCPROs around Ffuncall and Fapply calls. This
is safe because Ffuncall protects all of its arguments by itself. * charset.c (map_charset_for_dump): Remove redundant GCPRO. * eval.c (Fapply, apply1, call0, call1, call2, call3, call4, call5) (call6, call7): Likewise. Use compound literals where applicable. (run_hook_with_args_2): Use compound literal.
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c128
1 files changed, 21 insertions, 107 deletions
diff --git a/src/eval.c b/src/eval.c
index 9ff25859646..5f54c105444 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2274,12 +2274,10 @@ Thus, (apply '+ 1 2 '(3 4)) returns 10.
2274usage: (apply FUNCTION &rest ARGUMENTS) */) 2274usage: (apply FUNCTION &rest ARGUMENTS) */)
2275 (ptrdiff_t nargs, Lisp_Object *args) 2275 (ptrdiff_t nargs, Lisp_Object *args)
2276{ 2276{
2277 ptrdiff_t i; 2277 ptrdiff_t i, numargs, funcall_nargs;
2278 EMACS_INT numargs;
2279 register Lisp_Object spread_arg; 2278 register Lisp_Object spread_arg;
2280 register Lisp_Object *funcall_args; 2279 register Lisp_Object *funcall_args;
2281 Lisp_Object fun, retval; 2280 Lisp_Object fun, retval;
2282 struct gcpro gcpro1;
2283 USE_SAFE_ALLOCA; 2281 USE_SAFE_ALLOCA;
2284 2282
2285 fun = args [0]; 2283 fun = args [0];
@@ -2320,10 +2318,9 @@ usage: (apply FUNCTION &rest ARGUMENTS) */)
2320 /* Avoid making funcall cons up a yet another new vector of arguments 2318 /* Avoid making funcall cons up a yet another new vector of arguments
2321 by explicitly supplying nil's for optional values. */ 2319 by explicitly supplying nil's for optional values. */
2322 SAFE_ALLOCA_LISP (funcall_args, 1 + XSUBR (fun)->max_args); 2320 SAFE_ALLOCA_LISP (funcall_args, 1 + XSUBR (fun)->max_args);
2323 for (i = numargs; i < XSUBR (fun)->max_args;) 2321 for (i = numargs; i < XSUBR (fun)->max_args; /* nothing */)
2324 funcall_args[++i] = Qnil; 2322 funcall_args[++i] = Qnil;
2325 GCPRO1 (*funcall_args); 2323 funcall_nargs = 1 + XSUBR (fun)->max_args;
2326 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
2327 } 2324 }
2328 } 2325 }
2329 funcall: 2326 funcall:
@@ -2332,8 +2329,7 @@ usage: (apply FUNCTION &rest ARGUMENTS) */)
2332 if (!funcall_args) 2329 if (!funcall_args)
2333 { 2330 {
2334 SAFE_ALLOCA_LISP (funcall_args, 1 + numargs); 2331 SAFE_ALLOCA_LISP (funcall_args, 1 + numargs);
2335 GCPRO1 (*funcall_args); 2332 funcall_nargs = 1 + numargs;
2336 gcpro1.nvars = 1 + numargs;
2337 } 2333 }
2338 2334
2339 memcpy (funcall_args, args, nargs * word_size); 2335 memcpy (funcall_args, args, nargs * word_size);
@@ -2346,11 +2342,10 @@ usage: (apply FUNCTION &rest ARGUMENTS) */)
2346 spread_arg = XCDR (spread_arg); 2342 spread_arg = XCDR (spread_arg);
2347 } 2343 }
2348 2344
2349 /* By convention, the caller needs to gcpro Ffuncall's args. */ 2345 /* Ffuncall gcpro's all of its args. */
2350 retval = Ffuncall (gcpro1.nvars, funcall_args); 2346 retval = Ffuncall (funcall_nargs, funcall_args);
2351 UNGCPRO;
2352 SAFE_FREE ();
2353 2347
2348 SAFE_FREE ();
2354 return retval; 2349 return retval;
2355} 2350}
2356 2351
@@ -2558,41 +2553,22 @@ run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
2558void 2553void
2559run_hook_with_args_2 (Lisp_Object hook, Lisp_Object arg1, Lisp_Object arg2) 2554run_hook_with_args_2 (Lisp_Object hook, Lisp_Object arg1, Lisp_Object arg2)
2560{ 2555{
2561 Lisp_Object temp[3]; 2556 Frun_hook_with_args (3, ((Lisp_Object []) { hook, arg1, arg2 }));
2562 temp[0] = hook;
2563 temp[1] = arg1;
2564 temp[2] = arg2;
2565
2566 Frun_hook_with_args (3, temp);
2567} 2557}
2568 2558
2569/* Apply fn to arg. */ 2559/* Apply fn to arg. */
2570Lisp_Object 2560Lisp_Object
2571apply1 (Lisp_Object fn, Lisp_Object arg) 2561apply1 (Lisp_Object fn, Lisp_Object arg)
2572{ 2562{
2573 struct gcpro gcpro1; 2563 return (NILP (arg) ? Ffuncall (1, &fn)
2574 2564 : Fapply (2, ((Lisp_Object []) { fn, arg })));
2575 GCPRO1 (fn);
2576 if (NILP (arg))
2577 RETURN_UNGCPRO (Ffuncall (1, &fn));
2578 gcpro1.nvars = 2;
2579 {
2580 Lisp_Object args[2];
2581 args[0] = fn;
2582 args[1] = arg;
2583 gcpro1.var = args;
2584 RETURN_UNGCPRO (Fapply (2, args));
2585 }
2586} 2565}
2587 2566
2588/* Call function fn on no arguments. */ 2567/* Call function fn on no arguments. */
2589Lisp_Object 2568Lisp_Object
2590call0 (Lisp_Object fn) 2569call0 (Lisp_Object fn)
2591{ 2570{
2592 struct gcpro gcpro1; 2571 return Ffuncall (1, &fn);
2593
2594 GCPRO1 (fn);
2595 RETURN_UNGCPRO (Ffuncall (1, &fn));
2596} 2572}
2597 2573
2598/* Call function fn with 1 argument arg1. */ 2574/* Call function fn with 1 argument arg1. */
@@ -2600,14 +2576,7 @@ call0 (Lisp_Object fn)
2600Lisp_Object 2576Lisp_Object
2601call1 (Lisp_Object fn, Lisp_Object arg1) 2577call1 (Lisp_Object fn, Lisp_Object arg1)
2602{ 2578{
2603 struct gcpro gcpro1; 2579 return Ffuncall (2, ((Lisp_Object []) { fn, arg1 }));
2604 Lisp_Object args[2];
2605
2606 args[0] = fn;
2607 args[1] = arg1;
2608 GCPRO1 (args[0]);
2609 gcpro1.nvars = 2;
2610 RETURN_UNGCPRO (Ffuncall (2, args));
2611} 2580}
2612 2581
2613/* Call function fn with 2 arguments arg1, arg2. */ 2582/* Call function fn with 2 arguments arg1, arg2. */
@@ -2615,14 +2584,7 @@ call1 (Lisp_Object fn, Lisp_Object arg1)
2615Lisp_Object 2584Lisp_Object
2616call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2) 2585call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2)
2617{ 2586{
2618 struct gcpro gcpro1; 2587 return Ffuncall (3, ((Lisp_Object []) { fn, arg1, arg2 }));
2619 Lisp_Object args[3];
2620 args[0] = fn;
2621 args[1] = arg1;
2622 args[2] = arg2;
2623 GCPRO1 (args[0]);
2624 gcpro1.nvars = 3;
2625 RETURN_UNGCPRO (Ffuncall (3, args));
2626} 2588}
2627 2589
2628/* Call function fn with 3 arguments arg1, arg2, arg3. */ 2590/* Call function fn with 3 arguments arg1, arg2, arg3. */
@@ -2630,15 +2592,7 @@ call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2)
2630Lisp_Object 2592Lisp_Object
2631call3 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3) 2593call3 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
2632{ 2594{
2633 struct gcpro gcpro1; 2595 return Ffuncall (4, ((Lisp_Object []) { fn, arg1, arg2, arg3 }));
2634 Lisp_Object args[4];
2635 args[0] = fn;
2636 args[1] = arg1;
2637 args[2] = arg2;
2638 args[3] = arg3;
2639 GCPRO1 (args[0]);
2640 gcpro1.nvars = 4;
2641 RETURN_UNGCPRO (Ffuncall (4, args));
2642} 2596}
2643 2597
2644/* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */ 2598/* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */
@@ -2647,16 +2601,7 @@ Lisp_Object
2647call4 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, 2601call4 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2648 Lisp_Object arg4) 2602 Lisp_Object arg4)
2649{ 2603{
2650 struct gcpro gcpro1; 2604 return Ffuncall (5, ((Lisp_Object []) { fn, arg1, arg2, arg3, arg4 }));
2651 Lisp_Object args[5];
2652 args[0] = fn;
2653 args[1] = arg1;
2654 args[2] = arg2;
2655 args[3] = arg3;
2656 args[4] = arg4;
2657 GCPRO1 (args[0]);
2658 gcpro1.nvars = 5;
2659 RETURN_UNGCPRO (Ffuncall (5, args));
2660} 2605}
2661 2606
2662/* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */ 2607/* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */
@@ -2665,17 +2610,7 @@ Lisp_Object
2665call5 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, 2610call5 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2666 Lisp_Object arg4, Lisp_Object arg5) 2611 Lisp_Object arg4, Lisp_Object arg5)
2667{ 2612{
2668 struct gcpro gcpro1; 2613 return Ffuncall (6, ((Lisp_Object []) { fn, arg1, arg2, arg3, arg4, arg5 }));
2669 Lisp_Object args[6];
2670 args[0] = fn;
2671 args[1] = arg1;
2672 args[2] = arg2;
2673 args[3] = arg3;
2674 args[4] = arg4;
2675 args[5] = arg5;
2676 GCPRO1 (args[0]);
2677 gcpro1.nvars = 6;
2678 RETURN_UNGCPRO (Ffuncall (6, args));
2679} 2614}
2680 2615
2681/* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */ 2616/* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */
@@ -2684,18 +2619,8 @@ Lisp_Object
2684call6 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, 2619call6 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2685 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6) 2620 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6)
2686{ 2621{
2687 struct gcpro gcpro1; 2622 return Ffuncall (7, ((Lisp_Object [])
2688 Lisp_Object args[7]; 2623 { fn, arg1, arg2, arg3, arg4, arg5, arg6 }));
2689 args[0] = fn;
2690 args[1] = arg1;
2691 args[2] = arg2;
2692 args[3] = arg3;
2693 args[4] = arg4;
2694 args[5] = arg5;
2695 args[6] = arg6;
2696 GCPRO1 (args[0]);
2697 gcpro1.nvars = 7;
2698 RETURN_UNGCPRO (Ffuncall (7, args));
2699} 2624}
2700 2625
2701/* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */ 2626/* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */
@@ -2704,19 +2629,8 @@ Lisp_Object
2704call7 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, 2629call7 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2705 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6, Lisp_Object arg7) 2630 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6, Lisp_Object arg7)
2706{ 2631{
2707 struct gcpro gcpro1; 2632 return Ffuncall (8, ((Lisp_Object [])
2708 Lisp_Object args[8]; 2633 { fn, arg1, arg2, arg3, arg4, arg5, arg6, arg7 }));
2709 args[0] = fn;
2710 args[1] = arg1;
2711 args[2] = arg2;
2712 args[3] = arg3;
2713 args[4] = arg4;
2714 args[5] = arg5;
2715 args[6] = arg6;
2716 args[7] = arg7;
2717 GCPRO1 (args[0]);
2718 gcpro1.nvars = 8;
2719 RETURN_UNGCPRO (Ffuncall (8, args));
2720} 2634}
2721 2635
2722/* The caller should GCPRO all the elements of ARGS. */ 2636/* The caller should GCPRO all the elements of ARGS. */