Use a more efficient representation of the color table on the Options object

This commit is contained in:
Kovid Goyal
2021-06-03 22:17:37 +05:30
parent 2e71429b03
commit 79dd98b20e
9 changed files with 2404 additions and 287 deletions

View File

@@ -25,17 +25,13 @@ def option_names_for_completion() -> Tuple[str, ...]:
no_op_actions = frozenset({'noop', 'no-op', 'no_op'})
def build_ansi_color_table(opts: Optional[Options] = None) -> List[int]:
def build_ansi_color_table(opts: Optional[Options] = None) -> int:
if opts is None:
opts = defaults
def as_int(x: Tuple[int, int, int]) -> int:
return (x[0] << 16) | (x[1] << 8) | x[2]
def col(i: int) -> int:
return as_int(getattr(opts, 'color{}'.format(i)))
return list(map(col, range(256)))
addr, length = opts.color_table.buffer_info()
if length != 256 or opts.color_table.typecode != 'L':
raise TypeError(f'The color table has incorrect size length: {length} typecode: {opts.color_table.typecode}')
return addr
def atomic_save(data: bytes, path: str) -> None: