mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-17 13:42:49 +00:00
Collect stale hyperlinks before adding new links
This commit is contained in:
parent
dd5be07a45
commit
2ef024bbab
3 changed files with 12 additions and 3 deletions
|
|
@ -202,6 +202,8 @@ Detailed list of changes
|
|||
0.49.2 [future]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
- Preserve newly created hyperlinks during automatic hyperlink collection
|
||||
|
||||
- Reduce input latency by processing small amounts of program output, such as
|
||||
the echo of typed characters, immediately instead of waiting for
|
||||
:opt:`input_delay` (:pull:`10560`)
|
||||
|
|
|
|||
|
|
@ -143,6 +143,8 @@ get_id_for_hyperlink(Screen *screen, const char *id, const char *url) {
|
|||
key[keylen] = 0;
|
||||
hyperlink_map_itr itr = vt_get(&pool->map, key);
|
||||
if (!vt_is_end(itr)) return itr.data->val;
|
||||
// Collect before inserting the new hyperlink, which has no cell references yet.
|
||||
if (++pool->adds_since_last_gc > 8192) screen_garbage_collect_hyperlink_pool(screen);
|
||||
if (pool->array.count >= HYPERLINK_MAX_NUMBER - 1) {
|
||||
screen_garbage_collect_hyperlink_pool(screen);
|
||||
if (pool->array.count >= HYPERLINK_MAX_NUMBER - 128) {
|
||||
|
|
@ -159,9 +161,6 @@ get_id_for_hyperlink(Screen *screen, const char *id, const char *url) {
|
|||
hyperlink_id_type new_id = pool->array.count++;
|
||||
pool->array.items[new_id] = dupstr(key, keylen);
|
||||
if (vt_is_end(vt_insert(&pool->map, pool->array.items[new_id], new_id))) fatal("Out of memory");
|
||||
// If there have been a lot of hyperlink adds do a garbage collect so as
|
||||
// not to leak too much memory over unused hyperlinks
|
||||
if (++pool->adds_since_last_gc > 8192) screen_garbage_collect_hyperlink_pool(screen);
|
||||
return new_id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1470,6 +1470,14 @@ class TestScreen(BaseTest):
|
|||
self.ae('2', s.hyperlink_at(1, 3))
|
||||
self.ae(s.current_url_text(), 'Z Z')
|
||||
|
||||
def test_automatic_hyperlink_collection(self) -> None:
|
||||
s = self.create_screen()
|
||||
for i in range(1, 2 * 8192 + 3):
|
||||
url = f'https://example.test/{i}'
|
||||
parse_bytes(s, f'\r\x1b]8;;{url}\x1b\\L\x1b]8;;\x1b\\'.encode())
|
||||
self.ae(s.hyperlink_at(0, 0), url)
|
||||
self.assertLess(len(s.hyperlinks_as_set()), 8192)
|
||||
|
||||
def test_text_cache_garbage_collection(self):
|
||||
# unique multi-codepoint cell texts, single width base + combining mark
|
||||
def unique_text(i):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue