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/interface.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/interface.h') diff --git a/src/interface.h b/src/interface.h index b6c015b..6a391aa 100644 --- a/src/interface.h +++ b/src/interface.h @@ -160,12 +160,9 @@ void teco_interface_cleanup(void); * since sciteco.h should not depend on interface.h. */ -// FIXME: Should probably return the byte offset -static inline gboolean -teco_validate_pos(teco_int_t n) -{ - return !n || (n > 0 && teco_interface_ssm(SCI_POSITIONRELATIVE, 0, n) > 0); -} +gssize teco_glyphs2bytes(teco_int_t pos); +teco_int_t teco_bytes2glyphs(gsize pos); +gssize teco_glyphs2bytes_relative(gsize pos, teco_int_t n); static inline gboolean teco_validate_line(teco_int_t n) -- cgit v1.2.3