diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-07-25 01:55:28 +0200 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-07-25 01:55:28 +0200 |
| commit | 685507922b0b75da5935076395a5b1ec1ef58356 (patch) | |
| tree | bebc7c421856a6da363d2f9f7010b1ed211fee6c /src/doc.h | |
| parent | 378b9da1476cdcac14332b89f6286a450c4a7757 (diff) | |
revised and improved the Unicode glyph-to-byte conversion heuristics
Previously almost all glyph-to-byte offset conversions consulted
Scintilla's line index and counted characters on the resulting line.
For instance a simple expression like `.+1J` would scan the same line
twice completely, which would be very slow on pathologically long lines.
Even insertions did that due to having to update the ^Y ranges.
If you repeat such an operation over all characters as in `<.+1:J;>`
you would have complexity O(n^2) for n = line length.
Only commands with an explicit relative nature like `C` and `A` would
use teco_view_glyph2bytes_relative() which scans beginning at dot
as long as the relative movement is less than 1024 glyphs.
Wit the new heuristics almost all glyph-to-byte and byte-to-glyph
conversions can make use of that optimization.
This requires that dot must at all times be known in glyphs as well -
the byte position is managed by Scintilla (SCI_GETCURRENTPOS).
We therefore introduced teco_current_doc_set_dot() and
teco_current_doc_get_dot() to update dot in the current buffer or
Q-Register -- it cannot be stored along with the view since
Q-Registers share a single view.
A number of auxiliary functions have been introduced for
converting relative to a known (glyphs,bytes) offset pair
and for converting absolute and relative positions with regard
to the current doc and SCI_GETCURRENTPOS position.
Of course this is error-prone since the glyph and dot positions
are interdependant - they must always be kept in sync.
With these new optimizations even pathologically long lines can
(usually) be managed even in UTF-8 documents.
It does not address slow-downs in Scintilla's line layout, yet.
grosciteco.tes for instance runs twice as fast now.
Diffstat (limited to 'src/doc.h')
| -rw-r--r-- | src/doc.h | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -51,10 +51,17 @@ typedef struct { /* * The so called "parameters". + * They are all in bytes. * Updated/restored only when required */ - gint anchor, dot; - gint first_line, xoffset; + gsize anchor, pos; + guint first_line, xoffset; + + /** + * Dot in glyphs. + * This field is always kept up to date. + */ + teco_int_t dot; } teco_doc_t; /** @memberof teco_doc_t */ @@ -85,8 +92,9 @@ void teco_doc_update_from_doc(teco_doc_t *ctx, const teco_doc_t *from); static inline void teco_doc_reset(teco_doc_t *ctx) { - ctx->anchor = ctx->dot = 0; + ctx->anchor = ctx->pos = 0; ctx->first_line = ctx->xoffset = 0; + ctx->dot = 0; } /** @memberof teco_doc_t */ @@ -98,10 +106,12 @@ teco_doc_undo_reset(teco_doc_t *ctx) * and called with teco_undo_call() if we really * wanted to save more memory. */ - teco_undo_gint(ctx->anchor); - teco_undo_gint(ctx->dot); - teco_undo_gint(ctx->first_line); - teco_undo_gint(ctx->xoffset); + teco_undo_gsize(ctx->anchor); + teco_undo_gsize(ctx->pos); + teco_undo_guint(ctx->first_line); + teco_undo_guint(ctx->xoffset); + + teco_undo_int(ctx->dot); } void teco_doc_exchange(teco_doc_t *ctx, teco_doc_t *other); |
