[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/raeburn-startup f48e12c 06/17: Reduce nested calls
From: |
Ken Raeburn |
Subject: |
[Emacs-diffs] scratch/raeburn-startup f48e12c 06/17: Reduce nested calls during substitution. |
Date: |
Thu, 15 Dec 2016 11:33:18 +0000 (UTC) |
branch: scratch/raeburn-startup
commit f48e12c8192156d5390e24a29aa52fa7455d25ec
Author: Ken Raeburn <address@hidden>
Commit: Ken Raeburn <address@hidden>
Reduce nested calls during substitution.
* src/lread.c (substitute_object_recurse): If the cons cell's cdr slot
has another cons cell, process it iteratively instead of recursively.
---
src/lread.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/src/lread.c b/src/lread.c
index f0fdc7d..5e04c70 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3497,10 +3497,33 @@ substitute_object_recurse (Lisp_Object object,
Lisp_Object placeholder, Lisp_Obj
case Lisp_Cons:
{
- SUBSTITUTE (XCAR (subtree),
- XSETCAR (subtree, true_value));
- SUBSTITUTE (XCDR (subtree),
- XSETCDR (subtree, true_value));
+ /* It'd be easy enough to just process the car and cdr slots
+ recursively, but since we can't do tail recursion, a
+ 1000-element list produces 1000 recursive calls. Instead,
+ process the car slot recursively, but iterate over cdr
+ slots as long as it looks like a proper list. */
+ Lisp_Object pair = subtree;
+ while (XTYPE (pair) == Lisp_Cons)
+ {
+ Lisp_Object cdr;
+ SUBSTITUTE (XCAR (pair),
+ XSETCAR (pair, true_value));
+ cdr = XCDR (pair);
+ if (XTYPE (cdr) != Lisp_Cons)
+ break;
+ /* Duplicate the top-of-function processing specific to a
+ cons cell. */
+ if (EQ (placeholder, cdr))
+ break;
+ if (!EQ (Qnil, Fmemq (cdr, seen_list)))
+ break;
+ if (hash_lookup (XHASH_TABLE (read_objects_completed), cdr, NULL)
+ >= 0)
+ seen_list = Fcons (cdr, seen_list);
+ pair = cdr;
+ }
+ SUBSTITUTE (XCDR (pair),
+ XSETCDR (pair, true_value));
return subtree;
}
- [Emacs-diffs] branch scratch/raeburn-startup created (now 6a7d996), Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup 04b9ff6 03/17: Short-circuit substitutions for some simple types., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup 3b47eb4 02/17: Reduce lread substitutions., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup 3dd6aa7 13/17: Create *Messages* buffer when loading dumped data., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup f48e12c 06/17: Reduce nested calls during substitution.,
Ken Raeburn <=
- [Emacs-diffs] scratch/raeburn-startup 702bcad 15/17: Don't memset storage we're about to fill anyway., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup c95f727 16/17: Dump defvars for special variables only., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup 8e7ec27 07/17: Use a hash table for seen_list, similar to read_objects_map., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup dcc4b55 04/17: Replace read_objects assoc list with two hash tables., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup 8f37b82 08/17: Stefan's patch to write out and load "dumped.elc"; Oct 31 version., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup 872c9f6 05/17: Don't generate excessive hash tables during reads., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup 44f3368 11/17: Force purification off when using dumped.elc., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup 2fa607a 10/17: Increase the obarray size., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup 6120138 12/17: Don't get into an error loop if dumped.elc isn't found., Ken Raeburn, 2016/12/15
- [Emacs-diffs] scratch/raeburn-startup 913592c 14/17: Optimize reading of ASCII symbols from a .elc file., Ken Raeburn, 2016/12/15