tttm

git clone https://orangeshoelaces.net/git/tttm.git

3e13d808b1f67c2d0ab0105c88f7a0479d586488

Author: Vasily Kolobkov on 07/08/2017

Committer: Vasily Kolobkov on 07/08/2017

Offset parse tree pointers when switching to cache storage

Stats

parser.c | 26 ++++++++
1 file changed, 26 insertions(+)

Patch

diff --git a/parser.c b/parser.c
index b85f007..51482c5 100644
--- a/parser.c
+++ b/parser.c
@@ -167,6 +167,7 @@ static int par_free(struct parctx *);
 static int par_procure(struct parctx *, size_t, size_t);
 static int par_movewnd(struct parctx *, size_t);
 static int par_primecache(struct parctx *);
+static void par_offsetpt(union parnode *, union parnode *, off_t);
 static int par_prycache(struct parctx *, size_t);
 static int par_readnup(struct parctx *, size_t);
 static int par_peek(struct parctx *, size_t, char *);
@@ -540,6 +541,8 @@ par_primecache(struct parctx *p)
 	if (munmap(ci, p->buflen) == -1)
 		goto evm;
 
+	par_offsetpt(p->pt, p->ptend, off);
+
  exit:
 	return e;
  eio:
@@ -550,6 +553,29 @@ par_primecache(struct parctx *p)
 	goto exit;
 }
 
+void
+par_offsetpt(union parnode *cur, union parnode *end, off_t off)
+{
+	union parnode *iend;
+
+	while (cur < end) {
+		switch (cur->type) {
+		case PN_INTER:
+			iend = cur + cur->inter.len + 1;
+			par_offsetpt(cur + 1, MIN(iend, end), off);
+			cur = iend;
+			break;
+		case PN_STR:
+		case PN_QSTR:
+		case PN_LSTR:
+			cur->str.off += off;
+			/* fall through */
+		default:
+			cur++;
+		}
+	}
+}
+
 int
 par_prycache(struct parctx *p, size_t len)
 {