Skip to content

Commit

Permalink
Move Augment() and sorting back to Process().
Browse files Browse the repository at this point in the history
  • Loading branch information
dstein64 committed Aug 23, 2022
1 parent d223152 commit 5f52ed2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
12 changes: 6 additions & 6 deletions autoload/startuptime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,12 @@ function! s:Process(options, items) abort
let l:items = a:items
let l:startup = s:Startup(l:items)
let l:items = s:Consolidate(l:items)
let l:items = s:Augment(l:items, a:options)
if a:options.sort
let l:Compare = {i1, i2 ->
\ i1.time ==# i2.time ? 0 : (i1.time <# i2.time ? 1 : -1)}
call sort(l:items, l:Compare)
endif
if !empty(a:options.save)
" Saving the data is executed asynchronously with a callback. Otherwise,
" when s:Process is called through startuptime#Main, 'eventignore' would
Expand Down Expand Up @@ -1053,12 +1059,6 @@ function! startuptime#Main(file, winid, bufnr, options, items) abort
let l:event_width = g:startuptime_event_width
try
let [l:items, l:startup] = s:Process(a:options, a:items)
let l:items = s:Augment(l:items, a:options)
if a:options.sort
let l:Compare = {i1, i2 ->
\ i1.time ==# i2.time ? 0 : (i1.time <# i2.time ? 1 : -1)}
call sort(l:items, l:Compare)
endif
let l:processing_finished = 1
" Set 'modifiable' after :redraw so that e.g., if modifiable shows in
" the status line, it's display is not changed for the duration of
Expand Down
2 changes: 2 additions & 0 deletions doc/startuptime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ following example shows a `sourcing` event and an `other` event:
'mean': 0.006
},
'event': '--- NVIM STARTING ---',
'time': 0.006,
'tries': 1,
'type': 1,
'start': {
Expand All @@ -246,6 +247,7 @@ following example shows a `sourcing` event and an `other` event:
'mean': 0.053
},
'type': 0,
'time': 0.053,
'tries': 1,
'event': 'sourcing .../nvim/runtime/filetype.lua',
'start': {
Expand Down
12 changes: 8 additions & 4 deletions tests/test_startuptime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ call assert_true(len(g:save1.items) ># 1)
for s:item in g:save1.items
if s:item.type ==# g:save1.types['sourcing']
call assert_equal(
\ ['event', 'finish', 'occurrence', 'self', 'self+sourced', 'start', 'tries', 'type'],
\ ['event', 'finish', 'occurrence', 'self', 'self+sourced', 'start', 'time', 'tries', 'type'],
\ sort(copy(keys(s:item))))
call assert_equal(v:t_float, type(s:item['self+sourced'].mean))
call assert_equal(v:t_float, type(s:item['self'].mean))
call assert_false(isnan(s:item['self+sourced'].std))
call assert_false(isnan(s:item['self'].std))
call assert_equal(s:item['self+sourced'].mean, s:item['time'])
elseif s:item.type ==# g:save1.types['other']
call assert_equal(
\ ['elapsed', 'event', 'finish', 'occurrence', 'start', 'tries', 'type'],
\ ['elapsed', 'event', 'finish', 'occurrence', 'start', 'time', 'tries', 'type'],
\ sort(copy(keys(s:item))))
call assert_equal(v:t_float, type(s:item['elapsed'].mean))
call assert_false(isnan(s:item['elapsed'].std))
call assert_equal(s:item['elapsed'].mean, s:item['time'])
else
throw 'vim-startuptime: unknown type'
endif
Expand Down Expand Up @@ -67,18 +69,20 @@ call assert_true(len(g:save2.items) ># 1)
for s:item in g:save2.items
if s:item.type ==# g:save2.types['sourcing']
call assert_equal(
\ ['event', 'finish', 'occurrence', 'self', 'self+sourced', 'start', 'tries', 'type'],
\ ['event', 'finish', 'occurrence', 'self', 'self+sourced', 'start', 'time', 'tries', 'type'],
\ sort(copy(keys(s:item))))
call assert_equal(v:t_float, type(s:item['self+sourced'].mean))
call assert_equal(v:t_float, type(s:item['self'].mean))
call assert_true(isnan(s:item['self+sourced'].std))
call assert_true(isnan(s:item['self'].std))
call assert_equal(s:item['self+sourced'].mean, s:item['time'])
elseif s:item.type ==# g:save2.types['other']
call assert_equal(
\ ['elapsed', 'event', 'finish', 'occurrence', 'start', 'tries', 'type'],
\ ['elapsed', 'event', 'finish', 'occurrence', 'start', 'time', 'tries', 'type'],
\ sort(copy(keys(s:item))))
call assert_equal(v:t_float, type(s:item['elapsed'].mean))
call assert_true(isnan(s:item['elapsed'].std))
call assert_equal(s:item['elapsed'].mean, s:item['time'])
else
throw 'vim-startuptime: unknown type'
endif
Expand Down

0 comments on commit 5f52ed2

Please sign in to comment.