ZyX_I avatar ZyX_I committed dfab493

@aurum/log: More hg grapher optimizations

Comments (0)

Files changed (1)

plugin/aurum/log.vim

         let i+=1
     endfor
     let self.mapping[a:mapindex]=len(self.new_columns)
-    call add(self.new_columns, a:hex)
+    let self.new_columns+=[a:hex]
     return a:mapindex+2
 endfunction
 "▶2 graph.update_columns :: graph → + graph
     return text
 endfunction
 "▶1 glog
-"▶2 glog.utfedges
-function s:F.glog.utfedges(seen, hex, parents)
-    let nodeidx=index(a:seen, a:hex)
-    if nodeidx==-1
-        let nodeidx=len(a:seen)
-        call add(a:seen, a:hex)
+"▶2 glog.utf
+function s:F.glog.utf(state, type, seen, char, skip, cs, opts, repo)
+    let idx=index(a:seen, a:cs.hex)
+    if idx==-1
+        let idx=len(a:seen)
+        call add(a:seen, a:cs.hex)
     endif
     let knownparents=[]
     let newparents=[]
-    call map(copy(a:parents), 'add(((index(a:seen, v:val)==-1)?'.
-                    \               '(newparents):'.
-                    \               '(knownparents)), '.
-                    \             'v:val)')
+    call map(copy(a:cs.parents), 'add(((index(a:seen, v:val)==-1)?'.
+                    \                  '(newparents):'.
+                    \                  '(knownparents)), '.
+                    \                'v:val)')
     let ncols=len(a:seen)
-    call remove(a:seen, nodeidx)
-    call extend(a:seen, newparents, nodeidx)
-    let edges=map(knownparents, '['.nodeidx.', index(a:seen, v:val)]')
+    call remove(a:seen, idx)
+    call extend(a:seen, newparents, idx)
+    let edges=map(knownparents, '['.idx.', index(a:seen, v:val)]')
     if !empty(newparents)
-        call add(edges, [nodeidx, nodeidx])
-        if len(newparents)>1
-            call add(edges, [nodeidx, nodeidx+1])
-        endif
+        let edges+=[[idx, idx]]+((len(newparents)>1)?
+                    \                       ([[idx, idx+1]]):
+                    \                       ([]))
     endif
-    let nmorecols=len(a:seen)-ncols
-    return [nodeidx, edges, ncols, nmorecols]
-endfunction
-"▶2 glog.get_nodeline_edges_tail
-function s:F.glog.get_nodeline_edges_tail(node_index, p_node_index, n_columns,
-            \                             n_columns_diff, p_diff, fix_tail)
-    if a:fix_tail && a:n_columns_diff && a:n_columns_diff==a:p_diff
-        if a:n_columns_diff==-1
-            let start=max([a:node_index+1, a:p_node_index])
-            return repeat(['|', ' '], (start-a:node_index-1))+
-                        \repeat(['/', ' '], (a:n_columns-start))
-        else
-            return repeat(['\', ' '], (a:n_columns-a:node_index-1))
-        endif
-    else
-        return repeat(['|', ' '], (a:n_columns-a:node_index-1))
-    endif
-endfunction
-"▶2 glog.draw_edges
-function s:F.glog.draw_edges(edges, nodeline, interline)
-    for [start, end] in a:edges
-        if start==end+1
-            let a:interline[2*end   + 1]='/'
-        elseif start==end-1
-            let a:interline[2*start + 1]='\'
-        elseif start==end
-            let a:interline[2*start    ]='|'
-        else
-            let a:nodeline[2*end]='+'
-            if start>end
-                let [start, end]=[end, start]
-            endif
-            for i in filter(range(2*start+1, 2*end-1),
-                        \   'a:nodeline[v:val] isnot# "+"')
-                let a:nodeline[i]='-'
-            endfor
-        endif
-    endfor
-endfunction
-"▶2 glog.get_padding_line
-function s:F.glog.get_padding_line(ni, n_columns, edges)
-    let c=' '
-    if index(a:edges, [a:ni, a:ni-1])!=-1 || index(a:edges, [a:ni, a:ni])!=-1
-        let c='|'
-    endif
-    return repeat('| ', a:ni).c.' '.repeat('| ', (a:n_columns-a:ni-1))
-endfunction
-"▶2 glog.utf
-function s:F.glog.utf(state, type, coldata, char, skip, cs, opts, repo)
-    let [idx, edges, ncols, coldiff]=a:coldata
+    let coldiff=len(a:seen)-ncols
     let text=s:F.gettext(a:skip, a:cs, a:opts, a:repo, ncols)
     let add_padding_line=0
     let lnum = (has_key(text, 'text') ? len(text.text) : 0)
                         \                      '(v:val[0]+1)<v:val[1]'))
         endif
     endif
-    let fix_nodeline_tail = (lnum<=2 && !add_padding_line)
     let shift_interline=repeat(['|', ' '], idx)
     let nodeline=shift_interline+[a:char, ' ']+
-                \s:F.glog.get_nodeline_edges_tail(idx,     a:state[1], ncols,
-                \                                 coldiff, a:state[0],
-                \                                 fix_nodeline_tail)
+                \((lnum<=2 && !add_padding_line && coldiff &&
+                \  coldiff==a:state[0])?
+                \    ((coldiff==-1)?
+                \       (repeat(['|', ' '], max([idx+1, a:state[1]])-idx-1)+
+                \        repeat(['/', ' '], ncols-max([idx+1, a:state[1]]))):
+                \       (repeat(['\', ' '], (ncols-idx-1)))):
+                \    (repeat(['|', ' '], (ncols-idx-1))))
     let n_spaces=(1+((coldiff==-1)?(0):(1+(coldiff!=0))))
     let shift_interline+=repeat([' '],                    n_spaces)+
                 \        repeat(['/|\'[n_spaces-1], ' '], ncols-idx-1)
-    call s:F.glog.draw_edges(edges, nodeline, shift_interline)
+    for [start, end] in edges
+        if start==end+1
+            let shift_interline[2*end   + 1]='/'
+        elseif start==end-1
+            let shift_interline[2*start + 1]='\'
+        elseif start==end
+            let shift_interline[2*start    ]='|'
+        else
+            let nodeline[2*end]='+'
+            if start>end
+                let [start, end]=[end, start]
+            endif
+            for i in filter(range(2*start+1, 2*end-1),
+                        \   'nodeline[v:val] isnot# "+"')
+                let nodeline[i]='-'
+            endfor
+        endif
+    endfor
     let joined_nl=join(nodeline, '')
     let joined_sil=join(shift_interline, '')
     if has_key(text, 'skip')
     endif
     let lines=[joined_nl]
     if add_padding_line
-        call add(lines, s:F.glog.get_padding_line(idx, ncols, edges))
+        let lines+=[repeat('| ', idx).
+                    \   ((index(edges, [idx, idx-1])==-1 &&
+                    \     index(edges, [idx, idx])==-1)?(' '):('|')).
+                    \   ' '.repeat('| ', ncols-idx-1)]
     endif
-    call add(lines, joined_sil)
+    let lines+=[joined_sil]
     let ltdiff=lnum-len(lines)
     if ltdiff>0
-        let extra_interline=repeat('| ', ncols+coldiff)
-        let lines+=repeat([extra_interline], ltdiff)
+        let lines+=repeat([repeat('| ', ncols+coldiff)], ltdiff)
     else
         call extend(text.text, repeat([''], -ltdiff))
     endif
-    let indentation_level=2*max([ncols, ncols+coldiff])
     let a:state[0]=coldiff
     let a:state[1]=idx
-    call map(lines, 'printf("%-*s ", indentation_level, v:val)')
+    call map(lines, 'printf("%-*s ",'.(2*max([ncols, ncols+coldiff])).',v:val)')
     let curspecial=text.special
     let shiftlen=len(lines[0])
     call s:F.addcols(text.special, shiftlen)
     else
         let char=((index(a:d.showparents, a:cs.hex)==-1)?('o'):('@'))
     endif
-    let text=s:F.glog.utf(a:d.state, 'C',
-                \     s:F.glog.utfedges(a:d.seen, a:cs.hex, a:cs.parents), char,
-                \     skip, a:cs, a:d.opts, a:d.repo)
+    let text=s:F.glog.utf(a:d.state, 'C', a:d.seen, char,
+                \         skip, a:cs, a:d.opts, a:d.repo)
     if !has_key(text, 'text') || empty(text.text)
         return [[], 0, 0]
     endif
                     \  '            let self.lastline+=len(lines)',
                     \  '            let rectangle[1][0]=self.lastline-1',
                     \  '            let rectangle+=[cs.hex]',
-                    \  '            call add(self.rectangles, rectangle)',
+                    \  '            let self.rectangles+=[rectangle]',
                     \  '            let self.csstarts[cs.hex]=rectangle[0][0]',
                     \  '            if special isnot 0',
                     \  '                let self.specials[cs.hex]=special',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.