Re: processing character entities

Subject: Re: processing character entities
From: Alexander Taranov <tay@xxxxxxxxxx>
Date: Mon, 26 Jul 1999 11:02:09 +0400 (MSD)
Brandon Ibach writes:
 > Quoting Chris Maden <crism@xxxxxxxxxxx>:
 > > This is what I do.  It's really not that bad, just verbose.
 > > 
 > > (define (process-text #!optional (snl (current-node)))
 > >   ;; this part is inefficient; I need to rewrite this to carry a node
 > >   ;; index instead of an actual list of nodes
 > >   (let p-t-loop ((this-node (node-list-first (children snl)))
 > > 		   (other-nodes (node-list-rest (children snl))))
 > >        (if (node-list-empty? this-node)
 > > 	   (empty-sosofo)
 > > 	   (sosofo-append (case (node-property 'class-name
 > > 					       this-node)
 > > 			    ;; case clauses edited for brevity -BI
 > > 			  )
 > > 			  (if (node-list-empty? other-nodes)
 > > 			      (empty-sosofo)
 > > 			      (p-t-loop (node-list-first other-nodes)
 > > 					(node-list-rest other-nodes)))))))
 > > 
 >    In the interest of good practice (and possibly performance), you
 > may want to try this variation:
 > 
 > (define (process-text #!optional (snl (current-node)))
 >   (let p-t-loop ((this-node (node-list-first (children snl)))
 > 		 (other-nodes (node-list-rest (children snl)))
 > 		 (result (empty-sosofo)))
 >        (if (node-list-empty? this-node)
 > 	   result
 > 	   (p-t-loop (node-list-first other-nodes)
 > 		     (node-list-rest other-nodes)
 > 		     (sosofo-append result
 > 				    (case (node-property 'class-name
 > 							 this-node)
 > 			    ;; case clauses edited for brevity -BI
 > 				    ))))))
 > 
 >    This not only makes it tail-recursive, but also eliminates the
 > double check (at start and end) for the empty list.
 >    On this note, a question for the more Scheme-knowledgeable among us.
 > We know that a non-tail-recursive function will take up more space in
 > memory as the stack grows with each call, but what is the performance
 > impact?  Does the fix I've supplied above really have the potential to
 > make a significant impact?  If it saves even a little time on each
Yes, tail calls are not only save stack space but time also.
The difference is just difference between function call
and simple jump
 > iteration of the loop, I'd bet it could make a significant difference
 > in the overall running time of Chris' application, given that this
 > routine probably processes just about every data character and sdata
 > entity in his document.
 > 
 > -Brandon :)
 > 
 > 
 >  DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
 > 


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread