[racket-dev] [plt] Push #25666: master branch updated

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Fri Nov 9 19:40:59 EST 2012

Was it actually faster?

Robby

On Fri, Nov 9, 2012 at 5:46 PM,  <dyoo at racket-lang.org> wrote:
> dyoo has updated `master' from daca1c0d5b to 7618a6a737.
>   http://git.racket-lang.org/plt/daca1c0d5b..7618a6a737
>
> =====[ 2 Commits ]======================================================
> Directory summary:
>  100.0% collects/xml/private/
>
> ~~~~~~~~~~
>
> 641e855 Danny Yoo <dyoo at racket-lang.org> 2012-11-08 09:40
> :
> | Translate uses of display with write-string.
> |
> | Eli recommends that write-string should be faster in http://lists.racket-lang.org/dev/archive/2012-November/010764.html
> :
>   M collects/xml/private/writer.rkt | 14 +++++++++-----
>   M collects/xml/private/xexpr.rkt  | 29 ++++++++++++++---------------
>
> ~~~~~~~~~~
>
> 7618a6a Danny Yoo <dyoo at racket-lang.org> 2012-11-08 09:54
> :
> | Drop dead code.
> :
>   M collects/xml/private/xexpr.rkt | 16 ----------------
>
> =====[ Overall Diff ]===================================================
>
> collects/xml/private/writer.rkt
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> --- OLD/collects/xml/private/writer.rkt
> +++ NEW/collects/xml/private/writer.rkt
> @@ -168,15 +168,19 @@
>  (define (escape x table)
>    (regexp-replace* table x replace-escaped))
>
> -(define (display/escape x table out)
> -  (cond [(regexp-match table x)
> -         (display (escape x table) out)]
> +
> +;; write-string/excape: String Regexp Output-Port -> Void
> +;; Writes the string to the output port, with a fast-path
> +;; that tries to avoid using string escapes unless necessary.
> +(define (write-string/escape str table out)
> +  (cond [(regexp-match table str)
> +         (write-string (escape str table) out)]
>          [else
> -         (display x out)]))
> +         (write-string str out)]))
>
>
>  (provide escape
> -         display/escape
> +         write-string/escape
>           escape-table
>           escape-attribute-table
>           lowercase-symbol
>
> collects/xml/private/xexpr.rkt
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> --- OLD/collects/xml/private/xexpr.rkt
> +++ NEW/collects/xml/private/xexpr.rkt
> @@ -15,22 +15,6 @@
>
>  (define xexpr-drop-empty-attributes (make-parameter #f))
>
> -; : (a -> bool) tst -> bool
> -; To check if l is a (listof p?)
> -; Don't use (and (list? l) (andmap p? l)) because l may be improper.
> -(define (listof? p? l)
> -  (let listof-p? ([l l])
> -    (or (null? l)
> -        (and (cons? l) (p? (car l)) (listof-p? (cdr l))))))
> -
> -; : tst -> bool
> -(define (xexpr-attribute? b)
> -  (and (pair? b)
> -       (symbol? (car b))
> -       (pair? (cdr b))
> -       (string? (cadr b))
> -       (null? (cddr b))))
> -
>  ;; xml->xexpr : Content -> Xexpr
>  (define (xml->xexpr x)
>    (let* ([non-dropping-combine
> @@ -133,44 +117,43 @@
>               (values (cadr x) (cddr x))
>               (values null (cdr x))))
>         ; Write opening tag
> -       (display "<" out)
> +       (write-string "<" out)
>         (display name out)
>         ; Write attributes
>         (for ([att (in-list attrs)])
> -         (display " " out)
> +         (write-string " " out)
>           (display (car att) out)
> -         (display "=" out)
> -         (display "\"" out)
> -         (display/escape (cadr att) escape-attribute-table out)
> -         (display "\"" out))
> +         (write-string "=\"" out)
> +         (write-string/escape (cadr att) escape-attribute-table out)
> +         (write-string "\"" out))
>         ; Write end of opening tag
>         (if (and (null? content)
>                  (case short
>                      [(always) #t]
>                      [(never) #f]
>                      [else (memq (lowercase-symbol name) short)]))
> -           (display " />" out)
> +           (write-string " />" out)
>             (begin
> -             (display ">" out)
> +             (write-string ">" out)
>               ; Write body
>               (for ([xe (in-list content)])
>                 (loop xe))
>               ; Write closing tag
> -             (display "</" out)
> +             (write-string "</" out)
>               (display name out)
> -             (display ">" out)))]
> +             (write-string ">" out)))]
>        ; PCData
>        [(string? x)
> -       (display/escape x escape-table out)]
> +       (write-string/escape x escape-table out)]
>        ; Entities
>        [(symbol? x)
> -       (display "&" out)
> +       (write-string "&" out)
>         (display x out)
> -       (display ";" out)]
> +       (write-string ";" out)]
>        [(valid-char? x)
> -       (display "&#" out)
> +       (write-string "&#" out)
>         (display x out)
> -       (display ";" out)]
> +       (write-string ";" out)]
>        ; Embedded XML
>        [(cdata? x)
>         (write-xml-cdata x 0 void out)]

Posted on the dev mailing list.