This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository terminology.
View the commit online.
commit 5333240c63f386f9ebeafe6149be3e54eca479f3
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 20 12:33:02 2026 -0600
termptyesc: drop the link table on reset once no link is left
Cell copies, fills and scrolls keep hyperlink references counted only
once a terminal has a link table: without one, no cell can carry a link
id. The table was never freed, so a terminal that ever showed a
hyperlink stayed on the counting paths for good, even after RIS cleared
every link. In tybench, with a link and a RIS in front of each corpus,
dropping the table cuts the cycles of fill by 67%, insert 64%,
insert-mode 46%, scroll 37%, plain-ascii 22%, unicode 20%, long-lines
17%, scroll-region 16%, sgr 15% and rep 4%, which brings each back to
what it costs in a terminal that never showed a link.
RIS now drops the table when no link is left in it, which the other
screen may prevent. By then the reset has already freed the link the
termstate held, through term_link_free_if_unused(). termio may still
hold the id of a link it was hovering, so it looks links up through
term_link_get(), which knows a dropped table.
A table that failed to grow no longer leaves a size set without one:
once the table can be dropped, hl.size == 0 must mean that it is gone.
Corpora without links run the same instruction count before and after.
Their cycles moved by -0.4% to +1.4% in the default build, and by -0.5%
to +0.4% in a build with aligned functions and loops, so that is code
layout.
Measured with perf stat -e cycles:u, tybench -i 5, one process per
corpus pinned to one CPU, the median of 5 interleaved runs.
---
src/bin/termio.c | 16 +++++-----
src/bin/termpty.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++----
src/bin/termpty.h | 18 +++++++++--
src/bin/termptyesc.c | 2 ++
src/bin/tytest.c | 1 +
src/bin/unit_tests.h | 1 +
6 files changed, 110 insertions(+), 16 deletions(-)
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 39770553..f0d82e2c 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -1013,8 +1013,8 @@ termio_link_get(const Evas_Object *obj,
link = sd->link.string;
if (sd->link.id)
{
- Term_Link *hl = &sd->pty->hl.links[sd->link.id];
- if (!hl->url)
+ Term_Link *hl = term_link_get(sd->pty, sd->link.id);
+ if (!hl || !hl->url)
return NULL;
link = hl->url;
if (from_escape_code)
@@ -1478,9 +1478,9 @@ _cb_ctxp_link_content_copy(void *data,
if (sd->link.id)
{
- Term_Link *hl = &sd->pty->hl.links[sd->link.id];
+ Term_Link *hl = term_link_get(sd->pty, sd->link.id);
- if (!hl->url)
+ if (!hl || !hl->url)
return;
_termio_set_selection_text(sd, ELM_SEL_TYPE_CLIPBOARD, hl->url);
}
@@ -1690,8 +1690,8 @@ _cb_link_down(void *data,
if (!sd->link.string && sd->link.id)
{
- hl = &sd->pty->hl.links[sd->link.id];
- if (!hl->url)
+ hl = term_link_get(sd->pty, sd->link.id);
+ if (!hl || !hl->url)
return;
sd->link.string = eina_stringshare_add(hl->url);
}
@@ -2160,8 +2160,8 @@ _hyperlink_mouseover(Termio *sd,
termio_remove_links(sd);
sd->link.id = link_id;
- hl = &sd->pty->hl.links[link_id];
- if (!hl->url)
+ hl = term_link_get(sd->pty, link_id);
+ if (!hl || !hl->url)
return;
/* Scan the whole screen and display links as needed */
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 56b39016..185d1fed 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -2103,15 +2103,15 @@ term_link_new(Termpty *ty)
if (id >= ty->hl.size)
{
Term_Link *links;
- uint16_t old_size = ty->hl.size;
+ uint32_t old_size = ty->hl.size;
+ uint32_t size = old_size ? old_size * 2 : 512;
- if (!ty->hl.size)
- ty->hl.size = 256;
- links = realloc(ty->hl.links,
- ty->hl.size * 2 * sizeof(Term_Link));
+ /* a size is only set for the table that holds it: with no
+ * table, hl.size must stay 0 */
+ links = realloc(ty->hl.links, size * sizeof(Term_Link));
if (!links)
return NULL;
- ty->hl.size *= 2;
+ ty->hl.size = size;
ty->hl.links = links;
memset(ty->hl.links + old_size,
0,
@@ -2154,6 +2154,26 @@ term_link_free_if_unused(Termpty *ty, uint16_t link_id)
term_link_free(ty, ty->hl.links + link_id);
}
+void
+term_link_table_drop_if_empty(Termpty *ty)
+{
+ uint32_t i;
+
+ if (!ty->hl.links)
+ return;
+ /* id 0 is reserved, and always marked */
+ if (ty->hl.bitmap[0] != 1)
+ return;
+ for (i = 1; i < HL_LINKS_MAX / 8; i++)
+ {
+ if (ty->hl.bitmap[i])
+ return;
+ }
+ free(ty->hl.links);
+ ty->hl.links = NULL;
+ ty->hl.size = 0;
+}
+
#if defined(BINARY_TYFUZZ) || defined(BINARY_TYTEST)
/* Feed a NUL-terminated ASCII string as if the PTY sent it. */
@@ -4657,4 +4677,60 @@ tytest_osc8_no_leak(void)
}
#endif
+#if defined(BINARY_TYTEST)
+/* A reset drops the link table once no cell holds a link, so that a
+ * terminal that showed one takes the paths without link counting again; a
+ * link shown later gets a new table. */
+int
+tytest_links_reset(void)
+{
+ const Termcell *cells;
+ const Term_Link *link;
+ Termpty ty;
+ ssize_t w = 0;
+ uint32_t i;
+
+ _ty_test_init(&ty, 10, 3);
+ _ty_feed(&ty, "\033]8;;http://a\033\\link\033]8;;\033\\\r\n"
+ "1\r\n2\r\n3\r\n");
+ /* the link is in the scrollback too */
+ assert(termpty_backlog_length(&ty) >= 1);
+ assert(ty.hl.size != 0);
+
+ _ty_feed(&ty, "\033c");
+ assert(ty.hl.size == 0);
+ assert(!ty.hl.links);
+ assert(!term_link_get(&ty, 1));
+
+ _ty_feed(&ty, "\033]8;;http://b\033\\x\033]8;;\033\\");
+ cells = termpty_cellrow_get(&ty, 0, &w);
+ link = term_link_get(&ty, cells[0].att.link_id);
+ assert(link && link->url && !strcmp(link->url, "http://b"));
+
+ _ty_feed(&ty, "\033c");
+ assert(!ty.hl.links);
+
+ /* a link opened and not closed yet holds no cell, and goes with RIS */
+ _ty_feed(&ty, "\033]8;;http://d\033\\");
+ _ty_feed(&ty, "\033c");
+ assert(!ty.hl.links);
+
+ /* a link the other screen still shows keeps the table */
+ _ty_feed(&ty, "\033]8;;http://c\033\\y\033]8;;\033\\");
+ _ty_feed(&ty, "\033[?1049h");
+ _ty_feed(&ty, "\033c");
+ assert(ty.hl.links && ty.hl.size);
+ link = NULL;
+ for (i = 1; i < ty.hl.size && !link; i++)
+ {
+ if (ty.hl.links[i].url && !strcmp(ty.hl.links[i].url, "http://c"))
+ link = &ty.hl.links[i];
+ }
+ assert(link && link->refcount == 1);
+ _ty_test_shutdown(&ty);
+ free(ty.hl.links);
+ return 0;
+}
+#endif
+
#endif /* BINARY_TYFUZZ || BINARY_TYTEST */
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index f7271ab8..0f636211 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -462,6 +462,19 @@ void termpty_handle_block_codepoint_overwrite_heavy(Termpty *ty, int oldc, int n
Term_Link * term_link_new(Termpty *ty);
void term_link_free(Termpty *ty, Term_Link *link);
void term_link_free_if_unused(Termpty *ty, uint16_t link_id);
+/* Drops the whole link table once no link is left in it, as after a reset,
+ * so that the paths that keep links counted are skipped again. */
+void term_link_table_drop_if_empty(Termpty *ty);
+
+/* The link link_id, NULL for none, or for an id the table, dropped since,
+ * no longer holds. */
+static inline Term_Link *
+term_link_get(Termpty *ty, uint16_t link_id)
+{
+ if (!link_id || (link_id >= ty->hl.size))
+ return NULL;
+ return &ty->hl.links[link_id];
+}
int
termpty_color_class_get(Termpty *ty, const char *key,
@@ -522,8 +535,9 @@ do { \
} while (0)
/* No cell can carry a link id or a bit-31 block codepoint unless one was ever
- * created, so the bookkeeping loop is skippable. hl.size and block.blocks both
- * only ever go from unset to set. */
+ * created, so the bookkeeping loop is skippable. block.blocks only ever goes
+ * from unset to set; hl.size goes back to 0 only once no cell holds a link
+ * id, as term_link_table_drop_if_empty() drops the table. */
#define TERMPTY_CELL_COPY(Tpty, Tsrc, Tdst, N) \
do { \
if (EINA_UNLIKELY(((Tpty)->hl.size != 0) || ((Tpty)->block.blocks))) \
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index dcdf2dbe..6799708a 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -6585,6 +6585,8 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
/* RIS drops every program status record; DECSTR does not */
termpty_program_status_clear_all(ty);
termpty_clear_screen(ty, TERMPTY_CLR_ALL);
+ /* unless the other screen still shows some */
+ term_link_table_drop_if_empty(ty);
if (ty->cb.cancel_sel.func)
ty->cb.cancel_sel.func(ty->cb.cancel_sel.data);
return 1;
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 1ebfaf58..cdfc1c4e 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -76,6 +76,7 @@ static struct {
{ "hl_links_exhausted", tytest_hl_links_exhausted},
{ "termpty_read_error", tytest_termpty_read_error},
{ "osc8_no_leak", tytest_osc8_no_leak},
+ { "links_reset", tytest_links_reset},
{ "percent_decode", tytest_percent_decode},
{ "sgr_58_no_leak", tytest_sgr_58_no_leak},
{ "xmodkeys_set", tytest_xmodkeys_set},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 7d2bc3ee..ee7d72c9 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -49,6 +49,7 @@ int tytest_hl_links_free_full(void);
int tytest_hl_links_exhausted(void);
int tytest_termpty_read_error(void);
int tytest_osc8_no_leak(void);
+int tytest_links_reset(void);
int tytest_percent_decode(void);
int tytest_sgr_58_no_leak(void);
int tytest_xmodkeys_set(void);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.