cplay-ng

simple curses audio player
git clone https://git.ce9e.org/cplay-ng.git

commit
b693328517039cc4f22f3a23efb26dcac0a8cae9
parent
9d4b99fdd4d556a14f27a18d77fe946e659eea54
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-09-05 16:19
perf: cache relpath

Diffstat

M cplay.py 14 ++++++++++++--

1 files changed, 12 insertions, 2 deletions


diff --git a/cplay.py b/cplay.py

@@ -1,4 +1,5 @@
    1     1 import curses
   -1     2 import functools
    2     3 import os
    3     4 import random
    4     5 import re
@@ -81,6 +82,14 @@ def resize(*args):
   81    82     os.write(app.resize_out, b'.')
   82    83 
   83    84 
   -1    85 @functools.lru_cache()
   -1    86 def relpath(path):
   -1    87     if path.startswith(filelist.path):
   -1    88         return path[len(filelist.path) + 1:]
   -1    89     else:
   -1    90         return os.path.relpath(path)
   -1    91 
   -1    92 
   84    93 @contextmanager
   85    94 def enable_ctrl_keys():
   86    95     fd = sys.stdin.fileno()
@@ -262,7 +271,7 @@ class List:
  262   271         return False
  263   272 
  264   273     def format_item(self, item):
  265    -1         return os.path.relpath(item)
   -1   274         return relpath(item)
  266   275 
  267   276     def render(self):
  268   277         items = self.items[self.position:self.position + self.rows]
@@ -347,6 +356,7 @@ class Filelist(List):
  347   356         if path != self.path:
  348   357             self.path = path
  349   358             os.chdir(path)
   -1   359             relpath.cache_clear()
  350   360             self.search_cache = []
  351   361         self.all_items = []
  352   362         self.rsearch_str = ''
@@ -626,7 +636,7 @@ class Application:
  626   636         if self.input.active:
  627   637             status = self.input.prompt + self.input.str
  628   638         elif player.is_playing():
  629    -1             status = 'Playing %s' % os.path.relpath(player.path)
   -1   639             status = 'Playing %s' % relpath(player.path)
  630   640         else:
  631   641             status = ''
  632   642