Skip to content

Commit

Permalink
improve performance a little
Browse files Browse the repository at this point in the history
  • Loading branch information
Yggdroot committed May 27, 2021
1 parent 9973a86 commit 78bc54d
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions autoload/leaderf/python/leaderf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,16 +639,16 @@ def input(self, callback):
try:
self._history_index = 0
self._blinkon = True
idle = 10000
start = time.time()
update = False
prefix = ""

if lfEval("has('nvim') && exists('g:GuiLoaded')") == '1':
threshold = 2
else:
threshold = 25

while 1:
if len(self._instance._manager._content) < 60000:
threshold = 0.01
else:
threshold = 0.10

self._buildPrompt()
self._idle = False

Expand All @@ -664,15 +664,14 @@ def input(self, callback):
if lfEval("has('nvim') && exists('g:GuiLoaded')") == '1':
time.sleep(0.009) # this is to solve issue 375 leaderF hangs in nvim-qt

idle = min(idle + 1, 10000)
if update == True:
if idle >= threshold:
if time.time() - start >= threshold:
update = False
idle = 0
if ''.join(self._cmdline).startswith(prefix):
yield '<Update>'
else:
yield '<Shorten>'
start = time.time()
else:
try:
callback()
Expand All @@ -691,15 +690,14 @@ def input(self, callback):
if lfEval("has('nvim') && exists('g:GuiLoaded')") == '1':
time.sleep(0.009) # this is to solve issue 375 leaderF hangs in nvim-qt

idle = min(idle + 1, 10000)
if update == True:
if idle >= threshold:
if time.time() - start >= threshold:
update = False
idle = 0
if ''.join(self._cmdline).startswith(prefix):
yield '<Update>'
else:
yield '<Shorten>'
start = time.time()
else:
try:
callback()
Expand Down Expand Up @@ -728,12 +726,12 @@ def input(self, callback):
if self._pattern is None or (self._refine and self._pattern[1] == ''): # e.g. abc;
continue

if idle < threshold:
if time.time() - start < threshold:
continue
else:
update = False
idle = 0
yield '<Update>'
start = time.time()
else:
cmd = ''
for (key, value) in self._key_dict.items():
Expand Down Expand Up @@ -767,12 +765,12 @@ def input(self, callback):
self._backspace()
self._buildPattern()

if self._pattern and idle < threshold:
if self._pattern and time.time() - start < threshold:
continue
else:
idle = 0
update = False
yield '<Shorten>'
start = time.time()
elif equal(cmd, '<C-U>'):
if not self._pattern and self._refine == False:
continue
Expand Down

0 comments on commit 78bc54d

Please sign in to comment.