racket/private/serialize: eliminate unnecessary vector->list

This commit is contained in:
Philip McGrath 2019-07-01 15:29:34 -04:00 committed by Matthew Flatt
parent 0ebc43ef24
commit fce209d9f4

View File

@ -253,8 +253,10 @@
(set! cycle-stack (cons v cycle-stack)) (set! cycle-stack (cons v cycle-stack))
(cond (cond
[(serializable-struct? v) [(serializable-struct? v)
(let ([info (serializable-info v)]) (let* ([info (serializable-info v)]
(for-each loop (vector->list ((serialize-info-vectorizer info) v))))] [vec ((serialize-info-vectorizer info) v)])
(for ([x (in-vector vec)])
(loop x)))]
[(and (struct? v) [(and (struct? v)
(prefab-struct-key v)) (prefab-struct-key v))
(for-each loop (struct->list v))] (for-each loop (struct->list v))]
@ -266,7 +268,8 @@
;; No sub-structure ;; No sub-structure
(void)] (void)]
[(vector? v) [(vector? v)
(for-each loop (vector->list v))] (for ([x (in-vector v)])
(loop x))]
[(flvector? v) (void)] [(flvector? v) (void)]
[(fxvector? v) (void)] [(fxvector? v) (void)]
[(pair? v) [(pair? v)
@ -342,9 +345,10 @@
[(serializable-struct? v) [(serializable-struct? v)
(let ([info (serializable-info v)]) (let ([info (serializable-info v)])
(cons (mod-to-id info mod-map mod-map-cache deser-path->relative-path) (cons (mod-to-id info mod-map mod-map-cache deser-path->relative-path)
(map (serial #t) (let ([loop (serial #t)]
(vector->list [vec ((serialize-info-vectorizer info) v)])
((serialize-info-vectorizer info) v)))))] (for/list ([x (in-vector vec)])
(loop x)))))]
[(and (struct? v) [(and (struct? v)
(prefab-struct-key v)) (prefab-struct-key v))
=> (lambda (k) => (lambda (k)
@ -361,7 +365,10 @@
(cons 'p* v-rel) (cons 'p* v-rel)
(list* 'p+ (path->bytes v) (path-convention-type v))))] (list* 'p+ (path->bytes v) (path-convention-type v))))]
[(vector? v) [(vector? v)
(define elems (map (serial #t) (vector->list v))) (define elems
(let ([loop (serial #t)])
(for/list ([x (in-vector v)])
(loop x))))
(if (and (immutable? v) (if (and (immutable? v)
(andmap quotable? elems)) (andmap quotable? elems))
(cons 'q v) (cons 'q v)
@ -620,7 +627,7 @@
;; Prefab ;; Prefab
(let ([s (apply make-prefab-struct (let ([s (apply make-prefab-struct
(cadr v) (cadr v)
(vector->list (make-vector (cddr v) #f)))]) (make-list (cddr v) #f))])
(vector-set! fixup n (lambda (v) (vector-set! fixup n (lambda (v)
(let-values ([(si skipped?) (struct-info s)]) (let-values ([(si skipped?) (struct-info s)])
(let loop ([si si]) (let loop ([si si])