From 7c592561af3bbbad2eaf865247811ba2bd590c2e Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 29 Aug 2024 01:56:50 +0200 Subject: Glyph to byte offset mapping is now using the line character index (refs #5) * This works reasonably well unless lines are exceedingly long (as on a line we always count characters). The following test case is still slow (on Unicode buffers): 10000<@I/XX/> <%a-1:J;> While the following is now also fast: 10000<@I/X^J/> <%a-1:J;> * Commands with relative character offsets (C, R, A, D) have a special optimization where they always count characters beginning at dot, as long as the argument is now exceedingly large. This means they are fast even on exceedingly long lines. * The remaining commands (search, EC/EG, Xq) now accept glyph indexes. --- src/spawn.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/spawn.c') diff --git a/src/spawn.c b/src/spawn.c index 671f493..c1fb426 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -76,8 +76,8 @@ static struct { GSource *stdin_src, *stdout_src; gboolean interrupted; - teco_int_t from, to; - teco_int_t start; + gssize from, to; + gsize start; gboolean text_added; teco_eol_writer_t stdin_writer; @@ -202,15 +202,17 @@ teco_state_execute_initial(teco_machine_main_t *ctx, GError **error) break; } - default: + default: { /* pipe and replace character range */ - if (!teco_expressions_pop_num_calc(&teco_spawn_ctx.to, 0, error) || - !teco_expressions_pop_num_calc(&teco_spawn_ctx.from, 0, error)) + teco_int_t from, to; + if (!teco_expressions_pop_num_calc(&to, 0, error) || + !teco_expressions_pop_num_calc(&from, 0, error)) return FALSE; + teco_spawn_ctx.from = teco_glyphs2bytes(from); + teco_spawn_ctx.to = teco_glyphs2bytes(to); rc = teco_bool(teco_spawn_ctx.from <= teco_spawn_ctx.to && - teco_validate_pos(teco_spawn_ctx.from) && - teco_validate_pos(teco_spawn_ctx.to)); - break; + teco_spawn_ctx.from >= 0 && teco_spawn_ctx.to >= 0); + } } if (teco_is_failure(rc)) { -- cgit v1.2.3