changeset 71872:b20203b004f8

(Fthrow): Remove loop around Fsignal. (Feval, Fapply, Ffuncall): Optimize for no function indirection. Use original function name in all signaled errors. Simplify Fsignal calls (no return). (funcall_lambda): Simplify Fsignal calls (no return).
author Kim F. Storm <storm@cua.dk>
date Thu, 13 Jul 2006 13:43:50 +0000
parents dcd566ed4e9b
children 0048306da39e
files src/eval.c
diffstat 1 files changed, 46 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/eval.c	Thu Jul 13 13:43:44 2006 +0000
+++ b/src/eval.c	Thu Jul 13 13:43:50 2006 +0000
@@ -1289,16 +1289,14 @@
 {
   register struct catchtag *c;
 
-  while (1)
-    {
-      if (!NILP (tag))
-	for (c = catchlist; c; c = c->next)
-	  {
-	    if (EQ (c->tag, tag))
-	      unwind_to_catch (c, value);
-	  }
-      tag = Fsignal (Qno_catch, Fcons (tag, Fcons (value, Qnil)));
-    }
+  if (!NILP (tag))
+    for (c = catchlist; c; c = c->next)
+      {
+	if (EQ (c->tag, tag))
+	  unwind_to_catch (c, value);
+      }
+  Fsignal (Qno_catch, list2 (tag, value));
+  abort ();
 }
 
 
@@ -2166,7 +2164,12 @@
   /* At this point, only original_fun and original_args
      have values that will be used below */
  retry:
-  fun = Findirect_function (original_fun, Qnil);
+
+  /* Optimize for no indirection.  */
+  fun = original_fun;
+  if (SYMBOLP (fun) && !EQ (fun, Qunbound)
+      && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
+    fun = indirect_function (fun);
 
   if (SUBRP (fun))
     {
@@ -2182,7 +2185,7 @@
 
       if (XINT (numargs) < XSUBR (fun)->min_args ||
 	  (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs)))
-	return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
+	Fsignal (Qwrong_number_of_arguments, list2 (original_fun, numargs));
 
       if (XSUBR (fun)->max_args == UNEVALLED)
 	{
@@ -2285,11 +2288,13 @@
     val = apply_lambda (fun, original_args, 1);
   else
     {
+      if (EQ (fun, Qunbound))
+	Fsignal (Qvoid_function, Fcons (original_fun, Qnil));
       if (!CONSP (fun))
-	return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
+	Fsignal (Qinvalid_function, Fcons (original_fun, Qnil));
       funcar = Fcar (fun);
       if (!SYMBOLP (funcar))
-	return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
+	Fsignal (Qinvalid_function, Fcons (original_fun, Qnil));
       if (EQ (funcar, Qautoload))
 	{
 	  do_autoload (fun, original_fun);
@@ -2300,7 +2305,7 @@
       else if (EQ (funcar, Qlambda))
 	val = apply_lambda (fun, original_args, 1);
       else
-	return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
+	Fsignal (Qinvalid_function, Fcons (original_fun, Qnil));
     }
  done:
   CHECK_CONS_LIST ();
@@ -2345,7 +2350,10 @@
 
   numargs += nargs - 2;
 
-  fun = indirect_function (fun);
+  /* Optimize for no indirection.  */
+  if (SYMBOLP (fun) && !EQ (fun, Qunbound)
+      && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
+    fun = indirect_function (fun);
   if (EQ (fun, Qunbound))
     {
       /* Let funcall get the error */
@@ -2824,7 +2832,7 @@
      int nargs;
      Lisp_Object *args;
 {
-  Lisp_Object fun;
+  Lisp_Object fun, original_fun;
   Lisp_Object funcar;
   int numargs = nargs - 1;
   Lisp_Object lisp_numargs;
@@ -2861,11 +2869,15 @@
 
   CHECK_CONS_LIST ();
 
+  original_fun = args[0];
+
  retry:
 
-  fun = args[0];
-
-  fun = Findirect_function (fun, Qnil);
+  /* Optimize for no indirection.  */
+  fun = original_fun;
+  if (SYMBOLP (fun) && !EQ (fun, Qunbound)
+      && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
+    fun = indirect_function (fun);
 
   if (SUBRP (fun))
     {
@@ -2873,11 +2885,11 @@
 	  || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
 	{
 	  XSETFASTINT (lisp_numargs, numargs);
-	  return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil)));
+	  Fsignal (Qwrong_number_of_arguments, list2 (original_fun, lisp_numargs));
 	}
 
       if (XSUBR (fun)->max_args == UNEVALLED)
-	return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
+	Fsignal (Qinvalid_function, Fcons (original_fun, Qnil));
 
       if (XSUBR (fun)->max_args == MANY)
 	{
@@ -2949,21 +2961,23 @@
     val = funcall_lambda (fun, numargs, args + 1);
   else
     {
+      if (EQ (fun, Qunbound))
+	Fsignal (Qvoid_function, Fcons (original_fun, Qnil));
       if (!CONSP (fun))
-	return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
+	Fsignal (Qinvalid_function, Fcons (original_fun, Qnil));
       funcar = Fcar (fun);
       if (!SYMBOLP (funcar))
-	return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
+	Fsignal (Qinvalid_function, Fcons (original_fun, Qnil));
       if (EQ (funcar, Qlambda))
 	val = funcall_lambda (fun, numargs, args + 1);
       else if (EQ (funcar, Qautoload))
 	{
-	  do_autoload (fun, args[0]);
+	  do_autoload (fun, original_fun);
 	  CHECK_CONS_LIST ();
 	  goto retry;
 	}
       else
-	return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
+	Fsignal (Qinvalid_function, Fcons (original_fun, Qnil));
     }
  done:
   CHECK_CONS_LIST ();
@@ -3039,7 +3053,7 @@
       if (CONSP (syms_left))
 	syms_left = XCAR (syms_left);
       else
-	return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
+	Fsignal (Qinvalid_function, Fcons (fun, Qnil));
     }
   else if (COMPILEDP (fun))
     syms_left = AREF (fun, COMPILED_ARGLIST);
@@ -3052,8 +3066,8 @@
       QUIT;
 
       next = XCAR (syms_left);
-      while (!SYMBOLP (next))
-	next = Fsignal (Qinvalid_function, Fcons (fun, Qnil));
+      if (!SYMBOLP (next))
+	Fsignal (Qinvalid_function, Fcons (fun, Qnil));
 
       if (EQ (next, Qand_rest))
 	rest = 1;
@@ -3067,17 +3081,15 @@
       else if (i < nargs)
 	specbind (next, arg_vector[i++]);
       else if (!optional)
-	return Fsignal (Qwrong_number_of_arguments,
-			Fcons (fun, Fcons (make_number (nargs), Qnil)));
+	Fsignal (Qwrong_number_of_arguments, list2 (fun, make_number (nargs)));
       else
 	specbind (next, Qnil);
     }
 
   if (!NILP (syms_left))
-    return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
+    Fsignal (Qinvalid_function, Fcons (fun, Qnil));
   else if (i < nargs)
-    return Fsignal (Qwrong_number_of_arguments,
-		    Fcons (fun, Fcons (make_number (nargs), Qnil)));
+    Fsignal (Qwrong_number_of_arguments, list2 (fun, make_number (nargs)));
 
   if (CONSP (fun))
     val = Fprogn (XCDR (XCDR (fun)));