From 01a1f8cedee8d995f93e4adb5855a5ae979646e3 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 25 Aug 2005 01:52:10 +0000 Subject: [PATCH] minor pane optimization --- TODO.FACTOR.txt | 3 ++- library/compiler/compiler.factor | 4 ++++ library/syntax/prettyprint.factor | 2 +- library/tools/annotations.factor | 32 +++++++++++++++++++------------ library/tools/walker.factor | 3 +-- library/ui/panes.factor | 24 ++++++++++++----------- 6 files changed, 41 insertions(+), 27 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 4748801f3c..52abb45137 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -5,6 +5,8 @@ + ui: +- off-by-one error in pickup? +- closing ui does not stop timers - adding/removing timers automatically for animated gadgets - fix listener prompt display after presentation commands invoked - theme abstraction in ui @@ -13,7 +15,6 @@ - gaps in pack layout - find out why so many small bignums get consed - faster mouse tracking -- binary search to locate visible children of packs - rewrite frame layout for new style - an interior paint that is only painted on rollover and mouse press; use it for menu items. give menus a gradient background diff --git a/library/compiler/compiler.factor b/library/compiler/compiler.factor index 52d919d66a..f524662b97 100644 --- a/library/compiler/compiler.factor +++ b/library/compiler/compiler.factor @@ -63,3 +63,7 @@ M: compound (compile) ( word -- ) #! Compute a quotation into an uninterned word, for testing #! purposes. gensym [ swap define-compound ] keep dup compile execute ; + +\ optimize profile +\ linearize profile +\ simplify profile diff --git a/library/syntax/prettyprint.factor b/library/syntax/prettyprint.factor index 4c8b49c818..5137e4bfee 100644 --- a/library/syntax/prettyprint.factor +++ b/library/syntax/prettyprint.factor @@ -321,7 +321,7 @@ M: wrapper pprint* ( wrapper -- ) : short. ( object -- ) dup unparse-short swap write-object terpri ; -: [.] ( sequence -- ) [ unparse-short. ] each ; +: [.] ( sequence -- ) [ short. ] each ; : stack. reverse-slice [.] ; diff --git a/library/tools/annotations.factor b/library/tools/annotations.factor index 0f2c883426..1d3599705e 100644 --- a/library/tools/annotations.factor +++ b/library/tools/annotations.factor @@ -1,25 +1,23 @@ ! Copyright (C) 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: words +USING: interpreter io kernel lists math namespaces prettyprint +sequences strings test ; ! The annotation words let you flag a word for either tracing ! or single-stepping. Note that currently, words referring to -! annotated words cannot be compiled; and annotating a word has -! no effect of compiled calls to that word. -USING: interpreter io kernel lists namespaces prettyprint -sequences strings test ; - +! annotated words cannot be compiled. : annotate ( word quot -- | quot: word def -- def ) over >r >r dup word-def r> call r> swap define-compound ; inline : (watch) ( word def -- def ) [ - "===> Entering: " pick word-name append , \ print , - \ .s , + "===> Entering: " pick word-name append , + [ print .s ] % % - "===> Leaving: " swap word-name append , \ print , - \ .s , + "===> Leaving: " swap word-name append , + [ print .s ] % ] make-list ; : watch ( word -- ) @@ -31,6 +29,16 @@ sequences strings test ; #! Cause the word to start the code walker when executed. [ nip [ walk ] cons ] annotate ; -: timer ( word -- ) - #! Print the time taken to execute the word when it's called. - [ nip [ time ] cons ] annotate ; +: +@ ( n var -- ) dup get [ swap >r + r> ] when* set ; + +: with-profile ( quot word -- ) + millis >r >r call r> millis r> - swap global [ +@ ] bind ; + inline + +: (profile) ( word def -- def ) + [ , literalize , \ with-profile , ] make-list ; + +: profile ( word -- ) + #! When the word is called, time it, and add the time to + #! the value in a global variable named by the word. + [ (profile) ] annotate ; diff --git a/library/tools/walker.factor b/library/tools/walker.factor index b6fa1ea987..ed97dbedd0 100644 --- a/library/tools/walker.factor +++ b/library/tools/walker.factor @@ -15,8 +15,7 @@ sequences io strings vectors words ; : &r #! Print stepper call stack, as well as the currently #! executing quotation. - meta-cf get unparse-short. - meta-executing get . meta-r get stack. ; + meta-cf get short. meta-executing get . meta-r get stack. ; : &get ( var -- value ) #! Get stepper variable value. diff --git a/library/ui/panes.factor b/library/ui/panes.factor index ff31aab34d..d9102a76e3 100644 --- a/library/ui/panes.factor +++ b/library/ui/panes.factor @@ -66,24 +66,26 @@ M: pane focusable-child* ( pane -- editor ) : pane-clear ( pane -- ) dup pane-output clear-incremental pane-current clear-gadget ; -: pane-ignore? ( style text pane -- ? ) - #! If we already have stuff in the current pack, and there - #! is no style information or text to write, ignore it. - #! Otherwise, we either have a fancy style (like an icon - #! or gadget being output), or we want the current pack to - #! have a minimal height so we put the empty label there. - pane-current gadget-children empty? not - rot not and swap empty? and ; - : pane-write-1 ( style text pane -- ) - 3dup pane-ignore? [ + pick not pick empty? and [ 3drop ] [ >r r> pane-current add-gadget ] ifte ; +: prepare-print ( current -- gadget ) + #! Optimization: if line has 1 child, add the child. + dup gadget-children { + { [ dup empty? ] [ 2drop ""