From dd767bdf912b5d40203428e75aafde3aa340c1a5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 20 Oct 2016 14:21:25 +0530 Subject: [PATCH] Tighten up dirty_cells() --- kitty/term.py | 16 +++++++--------- kitty/utils.py | 11 ----------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/kitty/term.py b/kitty/term.py index 8ac57e301..656dca4e2 100644 --- a/kitty/term.py +++ b/kitty/term.py @@ -3,6 +3,7 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal from functools import lru_cache +from itertools import product from typing import Tuple, Iterator, Sequence from PyQt5.QtCore import pyqtSignal, QTimer, QRect, Qt @@ -11,7 +12,7 @@ from PyQt5.QtWidgets import QWidget from .config import build_ansi_color_tables, Options, fg_color_table, bg_color_table from .data_types import Line, Cursor, HAS_BG_MASK, COL_SHIFT, COL_MASK, as_color -from .utils import set_current_font_metrics, first_intersecting_bucket, last_intersecting_bucket +from .utils import set_current_font_metrics from .tracker import ChangeTracker from .screen import wrap_cursor_position from .keys import key_event_to_data @@ -151,14 +152,11 @@ class TerminalWidget(QWidget): self.pending_update = QRegion() def dirty_cells(self, region: QRegion) -> Iterator[Tuple[int]]: - for rect in region.rects(): - left, top, w, h = rect.getRect() - right, bottom = left + w, top + h - for lnum in range(min(0, first_intersecting_bucket(self.cell_height, top, self.vmargin)), - max(self.lines_per_screen - 1, last_intersecting_bucket(self.cell_height, bottom, self.vmargin))): - for cnum in range(min(0, first_intersecting_bucket(self.cell_width, left, self.hmargin)), - max(self.cells_per_line - 1, last_intersecting_bucket(self.cell_width, right, self.hmargin))): - yield lnum, cnum + lines = (l for l in range(self.lines_per_screen) if region.intersects(QRect( + self.hmargin, self.line_positions[l], self.cell_width * self.cells_per_line, self.cell_height))) + cells = (c for c in range(self.cells_per_line) if region.intersects(QRect( + self.cell_positions[c], self.vmargin, self.cell_width, self.cell_height * self.lines_per_screen))) + yield from product(lines, cells) def paintEvent(self, ev): if self.size() != self.layout_size: diff --git a/kitty/utils.py b/kitty/utils.py index 1a7948d41..d759ce329 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -3,7 +3,6 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal import os -import math import sys import termios import struct @@ -113,13 +112,3 @@ def timeit(name, do_timing=False): yield if do_timing: print('Time for {}: {}'.format(name, monotonic() - st)) - - -def first_intersecting_bucket(sz, boundary, offset=0): - ' Solve the eqn: offset + (n + 1) * sz >= boundary ' - return int(math.ceil((boundary - offset) / sz)) - 1 - - -def last_intersecting_bucket(sz, boundary, offset): - ' Solve the eqn: offset + n * sz <= boundary ' - return int(math.floor((boundary - offset) / sz))