Fix performance regression

db4
Slava Pestov 2008-09-27 17:54:51 -05:00
parent f5acf7e3d6
commit 91036cf323
2 changed files with 19 additions and 27 deletions

View File

@ -166,14 +166,13 @@ DEFER: relayout
DEFER: in-layout?
: do-invalidate ( gadget -- gadget )
in-layout? get [ dup invalidate ] [ dup invalidate* ] if ;
GENERIC: dim-changed ( gadget -- )
M: gadget dim-changed
in-layout? get [ invalidate ] [ invalidate* ] if ;
M: gadget (>>dim) ( dim gadget -- )
2dup dim>> =
[ 2drop ]
[ tuck call-next-method do-invalidate drop ]
if ;
2dup dim>> = [ 2drop ] [ tuck call-next-method dim-changed ] if ;
GENERIC: pref-dim* ( gadget -- dim )

View File

@ -4,17 +4,6 @@ USING: io kernel math namespaces math.vectors ui.gadgets
ui.gadgets.packs accessors math.geometry.rect ;
IN: ui.gadgets.incremental
! Incremental layout allows adding lines to panes to be O(1).
! Note that incremental packs are distinct from ordinary packs
! defined in layouts.factor, since you don't want all packs to
! be incremental. In particular, incremental packs do not
! support non-default values for pack-align, pack-fill and
! pack-gap.
! The cursor is the current size of the incremental pack.
! New gadgets are added at
! incremental-cursor gadget-orientation v*
TUPLE: incremental < pack cursor ;
: <incremental> ( -- incremental )
@ -29,29 +18,33 @@ M: incremental pref-dim*
: next-cursor ( gadget incremental -- cursor )
[
swap rect-dim swap cursor>>
2dup v+ >r vmax r>
[ rect-dim ] [ cursor>> ] bi*
[ vmax ] [ v+ ] 2bi
] keep orientation>> set-axis ;
: update-cursor ( gadget incremental -- )
[ next-cursor ] keep (>>cursor) ;
tuck next-cursor >>cursor drop ;
: incremental-loc ( gadget incremental -- )
[ cursor>> ] [ orientation>> ] bi v*
>>loc drop ;
: prefer-incremental ( gadget -- )
: prefer-incremental ( gadget -- ) USE: slots.private
dup forget-pref-dim dup pref-dim >>dim drop ;
M: incremental dim-changed drop ;
: add-incremental ( gadget incremental -- )
not-in-layout
2dup swap (add-gadget) drop
over prefer-incremental
over layout-later
2dup incremental-loc
tuck update-cursor
dup prefer-incremental
parent>> [ invalidate* ] when* ;
t in-layout? [
over prefer-incremental
over layout-later
2dup incremental-loc
tuck update-cursor
dup prefer-incremental
parent>> [ invalidate* ] when*
] with-variable ;
: clear-incremental ( incremental -- )
not-in-layout