git clone https://orangeshoelaces.net/git/tttm.git
Author: Vasily Kolobkov on 05/30/2016
Committer: Vasily Kolobkov on 05/30/2016
Make parser internal window as long as its buffer
parser.c | 34 ++++----
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/parser.c b/parser.c
index 2e1de9c..a263d48 100644
--- a/parser.c
+++ b/parser.c
@@ -131,8 +131,6 @@ static const char atom_specials[] = ASCII_CTL " \"%()*\\]{\x7f";
static const char tag_specials[] = ASCII_CTL " \"%()*+\\{\x7f";
-static const size_t wndcap = 1024;
-
struct parcur {
size_t off;
union parnode *pt;
@@ -142,6 +140,7 @@ struct parctx {
struct parcur cur;
int e;
char *wnd;
+ size_t wndcap;
size_t wndlee;
size_t wndoff;
union parnode *pt;
@@ -408,6 +407,7 @@ par_init(struct parctx *p, struct laxsrc *in, char *buf, size_t buflen,
bzero(p, sizeof(*p));
p->cur.pt = pt;
p->wnd = buf;
+ p->wndcap = buflen;
p->pt = pt;
p->ptend = pt + ptlen;
p->ptlen = ptlen;
@@ -425,7 +425,7 @@ par_free(struct parctx *p)
if (e = par_backup(p))
goto exit;
- if (p->strstor == SS_CACHE && munmap(p->wnd, wndcap) == -1)
+ if (p->strstor == SS_CACHE && munmap(p->wnd, p->wndcap) == -1)
goto evm;
exit:
return e;
@@ -439,7 +439,7 @@ par_free(struct parctx *p)
When reading from source to fulfill the request, no less than the needed
amount and anything over that that fits the window is transfered.
- precond: len <= wndcap
+ precond: len <= p->wndcap
*/
int
par_procure(struct parctx *p, size_t off, size_t len)
@@ -454,14 +454,14 @@ par_procure(struct parctx *p, size_t off, size_t len)
goto exit;
while (send > p->strlen) {
- if ((p->wndlee == wndcap) && (e = par_movewnd(p, p->strlen)))
+ if ((p->wndlee == p->wndcap) && (e = par_movewnd(p, p->strlen)))
goto exit;
- wndshort = MIN(send - p->strlen, wndcap - p->wndlee);
+ wndshort = MIN(send - p->strlen, p->wndcap - p->wndlee);
if ((e = par_readnup(p, wndshort)))
goto exit;
}
- if (off < p->wndoff || send > p->wndoff + wndcap)
+ if (off < p->wndoff || send > p->wndoff + p->wndcap)
e = par_movewnd(p, off);
exit:
return e;
@@ -474,7 +474,7 @@ par_movewnd(struct parctx *p, size_t off)
char *ci;
e = TE_OK;
- if (p->strstor == SS_MEM && off + wndcap <= p->buflen) {
+ if (p->strstor == SS_MEM && off + p->wndcap <= p->buflen) {
p->wnd = p->buf + off;
goto finwnd;
}
@@ -486,13 +486,13 @@ par_movewnd(struct parctx *p, size_t off)
if ((e = par_primecache(p)))
goto exit;
} else {
- if (munmap(p->wnd, wndcap) == -1)
+ if (munmap(p->wnd, p->wndcap) == -1)
goto evm;
}
- if ((e = par_prycache(p, off + wndcap)))
+ if ((e = par_prycache(p, off + p->wndcap)))
goto exit;
- ci = mmap(0, wndcap, PROT_READ | PROT_WRITE,
+ ci = mmap(0, p->wndcap, PROT_READ | PROT_WRITE,
MAP_SHARED, p->cache, p->corig + off);
if (ci == MAP_FAILED)
goto evm;
@@ -501,7 +501,7 @@ par_movewnd(struct parctx *p, size_t off)
goto finwnd;
finwnd:
- p->wndlee = MIN(wndcap, p->strlen - off);
+ p->wndlee = MIN(p->wndcap, p->strlen - off);
p->wndoff = off;
exit:
return e;
@@ -590,7 +590,7 @@ par_readnup(struct parctx *p, size_t n)
int e;
size_t hi, nr;
- hi = wndcap - p->wndlee;
+ hi = p->wndcap - p->wndlee;
nr = laxsrc_read(p->in, p->wnd + p->wndlee, n, hi, &e);
if (e == TE_OK && nr > 0) {
p->wndlee += nr;
@@ -623,11 +623,11 @@ par_backup(struct parctx *p)
size_t off, wndlag;
e = TE_OK;
- shed = p->cur.off / wndcap + 1;
- nwnd = p->strlen / wndcap + (p->strlen % wndcap > 0);
- off = (nwnd - 1) * wndcap;
+ shed = p->cur.off / p->wndcap + 1;
+ nwnd = p->strlen / p->wndcap + (p->strlen % p->wndcap > 0);
+ off = (nwnd - 1) * p->wndcap;
- for (w = nwnd; w >= shed; w--, off -= wndcap) {
+ for (w = nwnd; w >= shed; w--, off -= p->wndcap) {
if ((e = par_movewnd(p, off)))
break;