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)
            ,(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)
          ((null? li) result)
          ((null? (cdr li)) (cons (first li) result))
           (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 '())))



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 
For more options, visit

Reply via email to