summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-03 18:14:47 -0500
committerWormHeamer2026-01-03 18:14:47 -0500
commit9a4896c089d6678e5764122363ac0a47664deeba (patch)
tree67694da50748a5126db5cdd819b4e6157c38b59f
parent4f4e86e76be7acb303099148bf8814396bad81e0 (diff)
TxtHistNode distinct from TxtPieceTbl, with TxtLoc cur member
-rw-r--r--txt.c9
-rw-r--r--txt.h19
2 files changed, 16 insertions, 12 deletions
diff --git a/txt.c b/txt.c
index 07bd0bd..5d25aa8 100644
--- a/txt.c
+++ b/txt.c
@@ -242,7 +242,7 @@ void txt_load_empty(Txt *b) {
static inline int txt_hist_unchanged(Txt *t) {
if (t->hist.n < 1) return 0;
- TxtPieceTbl *pt = &t->hist.v[t->hist.i];
+ TxtHistNode *pt = &t->hist.v[t->hist.i];
if (t->ptbl.n != pt->n) return 0;
if (memcmp(pt->v, t->ptbl.v, sizeof(TxtPiece) * pt->n)) return 0;
return 1;
@@ -274,7 +274,7 @@ void txt_free(Txt *t) {
void txt_hist_push(Txt *t, TxtLoc cur) {
if (txt_hist_unchanged(t)) {
- t->hist.cur[t->hist.i] = cur;
+ t->hist.v[t->hist.i].cur = cur;
return;
}
if (t->hist.i + 1 < t->hist.n) t->hist.n = t->hist.i + 1;
@@ -282,7 +282,6 @@ void txt_hist_push(Txt *t, TxtLoc cur) {
if (t->hist.i == TXT_HIST_MAX) {
free(t->hist.v[0].v);
MOVE(&t->hist.v[0], &t->hist.v[1], TXT_HIST_MAX - 1);
- MOVE(&t->hist.cur[0], &t->hist.cur[1], TXT_HIST_MAX - 1);
memset(&t->hist.v[TXT_HIST_MAX - 1], 0, sizeof(*t->hist.v));
t->hist.i--;
t->hist.n--;
@@ -291,7 +290,7 @@ void txt_hist_push(Txt *t, TxtLoc cur) {
memcpy(t->hist.v[t->hist.i].v, t->ptbl.v, sizeof(TxtPiece) * t->ptbl.n);
t->hist.v[t->hist.i].n = t->ptbl.n;
t->hist.v[t->hist.i].dirty = t->ptbl.dirty;
- t->hist.cur[t->hist.i] = cur;
+ t->hist.v[t->hist.i].cur = cur;
t->hist.n++;
ASSERT(t->hist.n == t->hist.i + 1);
}
@@ -301,7 +300,7 @@ int txt_hist_set(Txt *t, TxtLoc *cur) {
DA_FIT(&t->ptbl, t->ptbl.n);
memcpy(t->ptbl.v, t->hist.v[t->hist.i].v, sizeof(TxtPiece) * t->ptbl.n);
t->ptbl.dirty = t->hist.v[t->hist.i].dirty;
- *cur = t->hist.cur[t->hist.i];
+ *cur = t->hist.v[t->hist.i].cur;
return 1;
}
diff --git a/txt.h b/txt.h
index 3f94c6d..521111d 100644
--- a/txt.h
+++ b/txt.h
@@ -23,11 +23,6 @@ typedef struct {
} TxtBuf;
typedef struct {
- DYNARR(TxtPiece);
- int dirty;
-} TxtPieceTbl;
-
-typedef struct {
struct Txt *t;
u32 p, i;
} TxtLoc;
@@ -39,8 +34,18 @@ typedef struct {
} TxtRange;
typedef struct {
- TxtPieceTbl v[TXT_HIST_MAX];
- TxtLoc cur[TXT_HIST_MAX];
+ DYNARR(TxtPiece);
+ int dirty;
+} TxtPieceTbl;
+
+typedef struct {
+ DYNARR(TxtPiece);
+ TxtLoc cur;
+ int dirty;
+} TxtHistNode;
+
+typedef struct {
+ TxtHistNode v[TXT_HIST_MAX];
u32 i, n;
} TxtHist;