Fixed time and space usage in cases where entity references

follow each other (thanks to Ivan Shvedunov for the report).

	* xml/xml-parse.lisp (P/CONTENT): Removed useless call to append.
	Use loop instead of tail recursion.
This commit is contained in:
dlichteblau
2007-10-03 15:21:56 +00:00
parent e7884fc9f7
commit 319149507a

View File

@ -2800,19 +2800,17 @@
(defun p/content (input) (defun p/content (input)
;; [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)* ;; [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)*
(loop
(multiple-value-bind (cat sem) (peek-token input) (multiple-value-bind (cat sem) (peek-token input)
(case cat (case cat
((:stag :ztag) ((:stag :ztag)
(p/element input) (p/element input))
(p/content input))
((:CDATA) ((:CDATA)
(process-characters input sem) (process-characters input sem)
(sax:characters (handler *ctx*) sem) (sax:characters (handler *ctx*) sem))
(p/content input))
((:ENTITY-REF) ((:ENTITY-REF)
(let ((name sem)) (let ((name sem))
(consume-token input) (consume-token input)
(append
(recurse-on-entity input name :general (recurse-on-entity input name :general
(lambda (input) (lambda (input)
(prog1 (prog1
@ -2821,24 +2819,20 @@
(external-entdef (p/ext-parsed-ent input))) (external-entdef (p/ext-parsed-ent input)))
(unless (eq (peek-token input) :eof) (unless (eq (peek-token input) :eof)
(wf-error input "Trailing garbage. - ~S" (wf-error input "Trailing garbage. - ~S"
(peek-token input)))))) (peek-token input))))))))
(p/content input))))
((:<!\[) ((:<!\[)
(let ((data (process-cdata-section input))) (let ((data (process-cdata-section input)))
(sax:start-cdata (handler *ctx*)) (sax:start-cdata (handler *ctx*))
(sax:characters (handler *ctx*) data) (sax:characters (handler *ctx*) data)
(sax:end-cdata (handler *ctx*))) (sax:end-cdata (handler *ctx*))))
(p/content input))
((:PI) ((:PI)
(consume-token input) (consume-token input)
(sax:processing-instruction (handler *ctx*) (car sem) (cdr sem)) (sax:processing-instruction (handler *ctx*) (car sem) (cdr sem)))
(p/content input))
((:COMMENT) ((:COMMENT)
(consume-token input) (consume-token input)
(sax:comment (handler *ctx*) sem) (sax:comment (handler *ctx*) sem))
(p/content input))
(otherwise (otherwise
nil)))) (return))))))
;; [78] extParsedEnt ::= TextDecl? contentw ;; [78] extParsedEnt ::= TextDecl? contentw
;; [79] extPE ::= TextDecl? extSubsetDecl ;; [79] extPE ::= TextDecl? extSubsetDecl