Move ClockMilliseconds to events, so fewer files are loaded some times

This commit is contained in:
w0rp
2018-06-19 20:53:49 +01:00
parent fd261d7a17
commit 82ea36576c
5 changed files with 20 additions and 20 deletions

View File

@@ -21,7 +21,7 @@ let s:timestamp_map = {}
" If the function throws an exception, then the function will not be called " If the function throws an exception, then the function will not be called
" for a while, and 0 will be returned instead. " for a while, and 0 will be returned instead.
function! ale#CallWithCooldown(timestamp_key, func, arglist) abort function! ale#CallWithCooldown(timestamp_key, func, arglist) abort
let l:now = ale#util#ClockMilliseconds() let l:now = ale#events#ClockMilliseconds()
if l:now < get(s:timestamp_map, a:timestamp_key, -1) if l:now < get(s:timestamp_map, a:timestamp_key, -1)
return 0 return 0

View File

@@ -779,7 +779,7 @@ endfunction
" The time taken will be a very rough approximation, and more time may be " The time taken will be a very rough approximation, and more time may be
" permitted than is specified. " permitted than is specified.
function! ale#engine#WaitForJobs(deadline) abort function! ale#engine#WaitForJobs(deadline) abort
let l:start_time = ale#util#ClockMilliseconds() let l:start_time = ale#events#ClockMilliseconds()
if l:start_time == 0 if l:start_time == 0
throw 'Failed to read milliseconds from the clock!' throw 'Failed to read milliseconds from the clock!'
@@ -810,7 +810,7 @@ function! ale#engine#WaitForJobs(deadline) abort
for l:job_id in l:job_list for l:job_id in l:job_list
if ale#job#IsRunning(l:job_id) if ale#job#IsRunning(l:job_id)
let l:now = ale#util#ClockMilliseconds() let l:now = ale#events#ClockMilliseconds()
if l:now - l:start_time > a:deadline if l:now - l:start_time > a:deadline
" Stop waiting after a timeout, so we don't wait forever. " Stop waiting after a timeout, so we don't wait forever.
@@ -847,7 +847,7 @@ function! ale#engine#WaitForJobs(deadline) abort
if l:has_new_jobs if l:has_new_jobs
" We have to wait more. Offset the timeout by the time taken so far. " We have to wait more. Offset the timeout by the time taken so far.
let l:now = ale#util#ClockMilliseconds() let l:now = ale#events#ClockMilliseconds()
let l:new_deadline = a:deadline - (l:now - l:start_time) let l:new_deadline = a:deadline - (l:now - l:start_time)
if l:new_deadline <= 0 if l:new_deadline <= 0

View File

@@ -1,15 +1,25 @@
" Author: w0rp <devw0rp@gmail.com> " Author: w0rp <devw0rp@gmail.com>
" Description: ALE functions for autocmd events. " Description: ALE functions for autocmd events.
" Get the number of milliseconds since some vague, but consistent, point in
" the past.
"
" This function can be used for timing execution, etc.
"
" The time will be returned as a Number.
function! ale#events#ClockMilliseconds() abort
return float2nr(reltimefloat(reltime()) * 1000)
endfunction
function! ale#events#QuitEvent(buffer) abort function! ale#events#QuitEvent(buffer) abort
" Remember when ALE is quitting for BufWrite, etc. " Remember when ALE is quitting for BufWrite, etc.
call setbufvar(a:buffer, 'ale_quitting', ale#util#ClockMilliseconds()) call setbufvar(a:buffer, 'ale_quitting', ale#events#ClockMilliseconds())
endfunction endfunction
function! ale#events#QuitRecently(buffer) abort function! ale#events#QuitRecently(buffer) abort
let l:time = getbufvar(a:buffer, 'ale_quitting', 0) let l:time = getbufvar(a:buffer, 'ale_quitting', 0)
return l:time && ale#util#ClockMilliseconds() - l:time < 1000 return l:time && ale#events#ClockMilliseconds() - l:time < 1000
endfunction endfunction
function! ale#events#SaveEvent(buffer) abort function! ale#events#SaveEvent(buffer) abort

View File

@@ -241,16 +241,6 @@ function! ale#util#InSandbox() abort
return 0 return 0
endfunction endfunction
" Get the number of milliseconds since some vague, but consistent, point in
" the past.
"
" This function can be used for timing execution, etc.
"
" The time will be returned as a Number.
function! ale#util#ClockMilliseconds() abort
return float2nr(reltimefloat(reltime()) * 1000)
endfunction
" Given a single line, or a List of lines, and a single pattern, or a List " Given a single line, or a List of lines, and a single pattern, or a List
" of patterns, return all of the matches for the lines(s) from the given " of patterns, return all of the matches for the lines(s) from the given
" patterns, using matchlist(). " patterns, using matchlist().

View File

@@ -11,12 +11,12 @@ After:
unlet! b:time_before unlet! b:time_before
Execute(QuitEvent should set b:ale_quitting some time from the clock): Execute(QuitEvent should set b:ale_quitting some time from the clock):
let b:time_before = ale#util#ClockMilliseconds() let b:time_before = ale#events#ClockMilliseconds()
call ale#events#QuitEvent(bufnr('')) call ale#events#QuitEvent(bufnr(''))
Assert b:ale_quitting >= b:time_before Assert b:ale_quitting >= b:time_before
Assert b:ale_quitting <= ale#util#ClockMilliseconds() Assert b:ale_quitting <= ale#events#ClockMilliseconds()
Execute(EnterEvent should set b:ale_quitting to 0): Execute(EnterEvent should set b:ale_quitting to 0):
let b:ale_quitting = 1 let b:ale_quitting = 1
@@ -29,11 +29,11 @@ Execute(The QuitRecently function should work when the variable isn't set):
AssertEqual 0, ale#events#QuitRecently(bufnr('')) AssertEqual 0, ale#events#QuitRecently(bufnr(''))
Execute(The QuitRecently function should return 1 when ALE quit recently): Execute(The QuitRecently function should return 1 when ALE quit recently):
let b:ale_quitting = ale#util#ClockMilliseconds() let b:ale_quitting = ale#events#ClockMilliseconds()
AssertEqual 1, ale#events#QuitRecently(bufnr('')) AssertEqual 1, ale#events#QuitRecently(bufnr(''))
Execute(The QuitRecently function should return 0 when a second has passed): Execute(The QuitRecently function should return 0 when a second has passed):
let b:ale_quitting = ale#util#ClockMilliseconds() - 1001 let b:ale_quitting = ale#events#ClockMilliseconds() - 1001
AssertEqual 0, ale#events#QuitRecently(bufnr('')) AssertEqual 0, ale#events#QuitRecently(bufnr(''))