gitk: Get rid of idrowranges and rowrangelist
Instead make the rowranges procedure compute its result by looking in the rowidlist entries for the rows around the children of the id and the id itself. This turns out not to take too long, and not having to maintain idrowranges and rowrangelist speeds up the layout. This also makes optimize_rows not use rowranges, since all it really needed was a way to work out if one id is the first child of another, so it can just look at the children list. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Aug 22, 2007 at 22:35 UTC
92ed666fa761554c67c8f883863517870a65376d
1 file changed
+66
-76
gitk
+66
-76
@@ -1927,7 +1927,7 @@ proc showview {n} {
1927
global curview viewdata viewfiles
1928
global displayorder parentlist rowidlist
1929
global colormap rowtextx commitrow nextcolor canvxmax
1930
- global numcommits rowrangelist commitlisted idrowranges rowchk
1930
+ global numcommits commitlisted rowchk
1931
global selectedline currentid canv canvy0
1932
global treediffs
1933
global pending_select phase
@@ -1963,13 +1963,13 @@ proc showview {n} {
1963
set vcmitlisted($curview) $commitlisted
1964
if {$phase ne {}} {
1965
set viewdata($curview) \
1966
- [list $phase $rowidlist {} $rowrangelist \
1967
- [flatten idrowranges] [flatten idinlist] \
1966
+ [list $phase $rowidlist {} {} \
1967
+ {} [flatten idinlist] \
1968
$rowlaidout $rowoptim $numcommits]
1969
} elseif {![info exists viewdata($curview)]
1970
|| [lindex $viewdata($curview) 0] ne {}} {
1971
set viewdata($curview) \
1972
- [list {} $rowidlist {} $rowrangelist]
1972
+ [list {} $rowidlist {} {}]
1973
}
1974
}
1975
catch {unset treediffs}
@@ -1998,12 +1998,9 @@ proc showview {n} {
1998
set parentlist $vparentlist($n)
1999
set commitlisted $vcmitlisted($n)
2000
set rowidlist [lindex $v 1]
2001
- set rowrangelist [lindex $v 3]
2001
if {$phase eq {}} {
2002
set numcommits [llength $displayorder]
2004
- catch {unset idrowranges}
2003
} else {
2006
- unflatten idrowranges [lindex $v 4]
2004
unflatten idinlist [lindex $v 5]
2005
set rowlaidout [lindex $v 6]
2006
set rowoptim [lindex $v 7]
@@ -2670,7 +2667,7 @@ proc idcol {idlist id {i 0}} {
2667
}
2668
2669
proc makeuparrow {oid y x} {
2673
- global rowidlist uparrowlen idrowranges displayorder
2670
+ global rowidlist uparrowlen displayorder
2671
2672
for {set i 0} {$i < $uparrowlen && $y > 1} {incr i} {
2673
incr y -1
@@ -2678,13 +2675,12 @@ proc makeuparrow {oid y x} {
2675
set x [idcol $idl $oid $x]
2676
lset rowidlist $y [linsert $idl $x $oid]
2677
}
2681
- lappend idrowranges($oid) [lindex $displayorder $y]
2678
}
2679
2680
proc initlayout {} {
2681
global rowidlist displayorder commitlisted
2682
global rowlaidout rowoptim
2687
- global idinlist rowchk rowrangelist idrowranges
2683
+ global idinlist rowchk
2684
global numcommits canvxmax canv
2685
global nextcolor
2686
global parentlist
@@ -2695,7 +2691,6 @@ proc initlayout {} {
2691
set displayorder {}
2692
set commitlisted {}
2693
set parentlist {}
2698
- set rowrangelist {}
2694
set nextcolor 0
2695
set rowidlist {{}}
2696
catch {unset idinlist}
@@ -2705,7 +2700,6 @@ proc initlayout {} {
2700
set canvxmax [$canv cget -width]
2701
catch {unset colormap}
2702
catch {unset rowtextx}
2708
- catch {unset idrowranges}
2703
set selectfirst 1
2704
}
2705
@@ -2952,9 +2946,8 @@ proc layoutrows {row endrow last} {
2946
global rowidlist displayorder
2947
global uparrowlen downarrowlen maxwidth mingaplen
2948
global children parentlist
2955
- global idrowranges
2949
global commitidx curview
2957
- global idinlist rowchk rowrangelist
2950
+ global idinlist rowchk
2951
2952
set idlist [lindex $rowidlist $row]
2953
while {$row < $endrow} {
@@ -2970,8 +2963,6 @@ proc layoutrows {row endrow last} {
2963
if {$r == 0} {
2964
set idlist [lreplace $idlist $x $x]
2965
set idinlist($i) 0
2973
- set rm1 [expr {$row - 1}]
2974
- lappend idrowranges($i) [lindex $displayorder $rm1]
2966
continue
2967
}
2968
set rowchk($i) [expr {$row + $r}]
@@ -3001,20 +2992,12 @@ proc layoutrows {row endrow last} {
2992
} else {
2993
unset idinlist($id)
2994
}
3004
- set ranges {}
3005
- if {[info exists idrowranges($id)]} {
3006
- set ranges $idrowranges($id)
3007
- lappend ranges $id
3008
- unset idrowranges($id)
3009
- }
3010
- lappend rowrangelist $ranges
2995
incr row
2996
set idlist [lreplace $idlist $col $col]
2997
set x $col
2998
foreach i $newolds {
2999
set x [idcol $idlist $i $x]
3000
set idlist [linsert $idlist $x $i]
3017
- set idrowranges($i) $id
3001
}
3002
foreach oid $oldolds {
3003
set x [idcol $idlist $oid $x]
@@ -3047,7 +3030,6 @@ proc addextraid {id row} {
3030
3031
proc layouttail {} {
3032
global rowidlist idinlist commitidx curview
3050
- global idrowranges rowrangelist
3033
3034
set row $commitidx($curview)
3035
set idlist [lindex $rowidlist $row]
@@ -3056,9 +3038,6 @@ proc layouttail {} {
3038
set id [lindex $idlist $col]
3039
addextraid $id $row
3040
catch {unset idinlist($id)}
3059
- lappend idrowranges($id) $id
3060
- lappend rowrangelist $idrowranges($id)
3061
- unset idrowranges($id)
3041
incr row
3042
set idlist [lreplace $idlist $col $col]
3043
lappend rowidlist $idlist
@@ -3069,9 +3048,6 @@ proc layouttail {} {
3048
addextraid $id $row
3049
lset rowidlist $row [list $id]
3050
makeuparrow $id $row 0
3072
- lappend idrowranges($id) $id
3073
- lappend rowrangelist $idrowranges($id)
3074
- unset idrowranges($id)
3051
incr row
3052
lappend rowidlist {}
3053
}
@@ -3092,7 +3068,7 @@ proc insert_pad {row col npad} {
3068
}
3069
3070
proc optimize_rows {row col endrow} {
3095
- global rowidlist displayorder
3071
+ global rowidlist displayorder curview children
3072
3073
if {$row < 1} {
3074
set row 1
@@ -3131,8 +3107,9 @@ proc optimize_rows {row col endrow} {
3107
}
3108
}
3109
if {$z0 eq {}} {
3134
- set ranges [rowranges $id]
3135
- if {$ranges ne {} && $y0 > [lindex $ranges 0]} {
3110
+ # if row y0 is the first child of $id then it's not an arrow
3111
+ if {[lindex $children($curview,$id) 0] ne
3112
+ [lindex $displayorder $y0]} {
3113
set isarrow 1
3114
}
3115
}
@@ -3195,11 +3172,10 @@ proc optimize_rows {row col endrow} {
3172
set x0 [lsearch -exact $previdlist $id]
3173
if {$x0 < 0} {
3174
# check if this is the link to the first child
3198
- set ranges [rowranges $id]
3199
- if {$ranges ne {} && $row == [lindex $ranges 0]} {
3175
+ set kid [lindex $displayorder $y0]
3176
+ if {[lindex $children($curview,$id) 0] eq $kid} {
3177
# it is, work out offset to child
3201
- set id [lindex $displayorder $y0]
3202
- set x0 [lsearch -exact $previdlist $id]
3178
+ set x0 [lsearch -exact $previdlist $kid]
3179
}
3180
}
3181
if {$x0 <= $col} break
@@ -3236,24 +3212,59 @@ proc linewidth {id} {
3212
}
3213
3214
proc rowranges {id} {
3239
- global phase idrowranges commitrow rowlaidout rowrangelist curview
3215
+ global commitrow curview children uparrowlen downarrowlen
3216
+ global rowidlist
3217
3241
- set ranges {}
3242
- if {$phase eq {} ||
3243
- ([info exists commitrow($curview,$id)]
3244
- && $commitrow($curview,$id) < $rowlaidout)} {
3245
- set ranges [lindex $rowrangelist $commitrow($curview,$id)]
3246
- } elseif {[info exists idrowranges($id)]} {
3247
- set ranges $idrowranges($id)
3248
- }
3249
- set linenos {}
3250
- foreach rid $ranges {
3251
- lappend linenos $commitrow($curview,$rid)
3218
+ set kids $children($curview,$id)
3219
+ if {$kids eq {}} {
3220
+ return {}
3221
}
3253
- if {$linenos ne {}} {
3254
- lset linenos 0 [expr {[lindex $linenos 0] + 1}]
3222
+ set ret {}
3223
+ lappend kids $id
3224
+ foreach child $kids {
3225
+ if {![info exists commitrow($curview,$child)]} break
3226
+ set row $commitrow($curview,$child)
3227
+ if {![info exists prev]} {
3228
+ lappend ret [expr {$row + 1}]
3229
+ } else {
3230
+ if {$row <= $prevrow} {
3231
+ puts "oops children out of order [shortids $id] $row < [shortids $prev] $prevrow"
3232
+ }
3233
+ # see if the line extends the whole way from prevrow to row
3234
+ if {$row > $prevrow + $uparrowlen + $downarrowlen &&
3235
+ [lsearch -exact [lindex $rowidlist \
3236
+ [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
3237
+ # it doesn't, see where it ends
3238
+ set r [expr {$prevrow + $downarrowlen}]
3239
+ if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
3240
+ while {[incr r -1] > $prevrow &&
3241
+ [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
3242
+ } else {
3243
+ while {[incr r] <= $row &&
3244
+ [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
3245
+ incr r -1
3246
+ }
3247
+ lappend ret $r
3248
+ # see where it starts up again
3249
+ set r [expr {$row - $uparrowlen}]
3250
+ if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
3251
+ while {[incr r] < $row &&
3252
+ [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
3253
+ } else {
3254
+ while {[incr r -1] >= $prevrow &&
3255
+ [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
3256
+ incr r
3257
+ }
3258
+ lappend ret $r
3259
+ }
3260
+ }
3261
+ if {$child eq $id} {
3262
+ lappend ret $row
3263
+ }
3264
+ set prev $id
3265
+ set prevrow $row
3266
}
3256
- return $linenos
3267
+ return $ret
3268
}
3269
3270
proc drawlineseg {id row endrow arrowlow} {
@@ -3938,7 +3949,7 @@ proc show_status {msg} {
3949
proc insertrow {row newcmit} {
3950
global displayorder parentlist commitlisted children
3951
global commitrow curview rowidlist numcommits
3941
- global rowrangelist rowlaidout rowoptim numcommits
3952
+ global rowlaidout rowoptim numcommits
3953
global selectedline rowchk commitidx
3954
3955
if {$row >= $numcommits} {
@@ -3970,18 +3981,6 @@ proc insertrow {row newcmit} {
3981
}
3982
set rowidlist [linsert $rowidlist $row $idlist]
3983
3973
- set rowrangelist [linsert $rowrangelist $row {}]
3974
- if {[llength $kids] > 1} {
3975
- set rp1 [expr {$row + 1}]
3976
- set ranges [lindex $rowrangelist $rp1]
3977
- if {$ranges eq {}} {
3978
- set ranges [list $newcmit $p]
3979
- } elseif {[lindex $ranges end-1] eq $p} {
3980
- lset ranges end-1 $newcmit
3981
- }
3982
- lset rowrangelist $rp1 $ranges
3983
- }
3984
-
3984
catch {unset rowchk}
3985
3986
incr rowlaidout
@@ -3998,7 +3997,7 @@ proc insertrow {row newcmit} {
3997
proc removerow {row} {
3998
global displayorder parentlist commitlisted children
3999
global commitrow curview rowidlist numcommits
4001
- global rowrangelist idrowranges rowlaidout rowoptim numcommits
4000
+ global rowlaidout rowoptim numcommits
4001
global linesegends selectedline rowchk commitidx
4002
4003
if {$row >= $numcommits} {
@@ -4026,15 +4025,6 @@ proc removerow {row} {
4025
4026
set rowidlist [lreplace $rowidlist $row $row]
4027
4029
- set rowrangelist [lreplace $rowrangelist $row $row]
4030
- if {[llength $kids] > 0} {
4031
- set ranges [lindex $rowrangelist $row]
4032
- if {[lindex $ranges end-1] eq $id} {
4033
- set ranges [lreplace $ranges end-1 end]
4034
- lset rowrangelist $row $ranges
4035
- }
4036
- }
4037
-
4028
catch {unset rowchk}
4029
4030
incr rowlaidout -1