According to profiling, the following sxml-handling function (consolidate sxp) is a major bottleneck in my application. It reduces all subsequent sxml text elements with the same attributes to one and is part of exporting from text% to xml.
I'm not used to optimizing Racket code. Does somebody have advice on how to optimize this? (define (mergable-text-elements? elem1 elem2) (and (equal? 'text (sxml:element-name elem2)) (equal? 'text (sxml:element-name elem1)) (equal? (sxml:attr-list elem1) (sxml:attr-list elem2)))) (define (merge-text-elements elem1 elem2) (define attr (sxml:attr-list-node elem1)) (if attr `(,(sxml:element-name elem1) ,attr ,(string-append (sxml:text elem1) (sxml:text elem2))) `(,(sxml:element-name elem1) ,(string-append (sxml:text elem1) (sxml:text elem2))))) (define (consolidate sxp) (define (consolidate-aux li result) (cond ((null? li) result) ((null? (cdr li)) (cons (first li) result)) (else (if (mergable-text-elements? (first li) (second li)) (consolidate-aux (cons (merge-text-elements (first li) (second li))(cddr li)) result) (consolidate-aux (cdr li) (cons (first li) result)))))) (reverse (consolidate-aux sxp '()))) Best, Erich -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.