[html-table] compact gnc:html-table-prepend-row!

This commit is contained in:
Christopher Lam 2019-10-09 20:12:59 +08:00
parent 49e6513042
commit d45f06215f

View File

@ -340,35 +340,28 @@
'())) '()))
(define (gnc:html-table-prepend-row! table newrow) (define (gnc:html-table-prepend-row! table newrow)
(let* ((dd (gnc:html-table-data table)) (let* ((new-num-rows (1+ (gnc:html-table-num-rows table)))
(current-num-rows (gnc:html-table-num-rows table)) (newrow-list (if (list? newrow) newrow (list newrow)))
(new-num-rows (+ current-num-rows 1)) (dd (append (gnc:html-table-data table) (list newrow-list))))
(newrow-list (if (list? newrow) newrow (list newrow)))) (gnc:html-table-set-num-rows-internal! table new-num-rows)
(set! dd (append dd (list newrow-list)))
(gnc:html-table-set-num-rows-internal!
table
new-num-rows)
(gnc:html-table-set-data! table dd) (gnc:html-table-set-data! table dd)
;; have to bump up the row index of the row styles and row markup ;; have to bump up the row index of the row styles and row markup
;; table on a prepend. just another reason you probably don't ;; table on a prepend. just another reason you probably don't
;; want to prepend. ;; want to prepend.
(let ((new-rowstyles (make-hash-table 21))) (let ((new-rowstyles (make-hash-table 21)))
(hash-fold (hash-for-each
(lambda (row style prev) (lambda (row style)
(hash-set! new-rowstyles (+ 1 row) style) (hash-set! new-rowstyles (+ 1 row) style))
#f) (gnc:html-table-row-styles table))
#f (gnc:html-table-row-styles table))
(gnc:html-table-set-row-styles! table new-rowstyles)) (gnc:html-table-set-row-styles! table new-rowstyles))
(let ((new-rowmarkup (make-hash-table 21))) (let ((new-rowmarkup (make-hash-table 21)))
(hash-fold (hash-for-each
(lambda (row markup prev) (lambda (row markup)
(hash-set! new-rowmarkup (+ 1 row) markup) (hash-set! new-rowmarkup (+ 1 row) markup))
#f) (gnc:html-table-row-markup-table table))
#f (gnc:html-table-row-markup-table table))
(gnc:html-table-set-row-markup-table! table new-rowmarkup)) (gnc:html-table-set-row-markup-table! table new-rowmarkup))
new-num-rows)) new-num-rows))
;; list-set! is 0-based... ;; list-set! is 0-based...