diff options
author | Daniel Shahaf <d.s@daniel.shahaf.name> | 2020-03-19 21:14:42 +0000 |
---|---|---|
committer | Daniel Shahaf <d.s@daniel.shahaf.name> | 2020-03-22 02:23:52 +0000 |
commit | 4960699de2fd010598d14d59f4bcd3d9b48ec46b (patch) | |
tree | 22e266288bbf1ab09035c79989e727190a87f13f | |
parent | be73026b07decc3990b2a345c42a8f7b74d8f83d (diff) | |
download | zsh-4960699de2fd010598d14d59f4bcd3d9b48ec46b.tar.gz zsh-4960699de2fd010598d14d59f4bcd3d9b48ec46b.tar.xz zsh-4960699de2fd010598d14d59f4bcd3d9b48ec46b.zip |
45583/0003: internal: Add some comments around Eccstr. No functional change.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | Src/parse.c | 31 | ||||
-rw-r--r-- | Src/zsh.h | 24 |
3 files changed, 52 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog index b73089f91..976d10fd7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2020-03-22 Daniel Shahaf <d.s@daniel.shahaf.name> + * 45583/0003: Src/parse.c, Src/zsh.h: internal: Add some comments + around Eccstr. No functional change. + * 45583/0002: Src/parse.c: internal: Reduce some variables' visibility. No functional change. diff --git a/Src/parse.c b/Src/parse.c index bd974a573..170e07298 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -253,13 +253,24 @@ struct heredocs *hdocs; * to avoid a lot of string parsing and some more string duplication. */ -static int eclen, ecused, ecnpats; +/* Number of wordcodes allocated. */ +static int eclen; +/* Number of wordcodes populated. */ +static int ecused; +/* Number of patterns... */ +static int ecnpats; static Wordcode ecbuf; static Eccstr ecstrs; -static int ecsoffs, ecssub, ecnfunc; +static int ecsoffs, ecssub; + +/* + * ### The number of starts and ends of function definitions up to this point. + * Never decremented. + */ +static int ecnfunc; #define EC_INIT_SIZE 256 #define EC_DOUBLE_THRESHOLD 32768 @@ -363,7 +374,11 @@ ecispace(int p, int n) ecadjusthere(p, n); } -/* Add one wordcode. */ +/* + * Add one wordcode. + * + * Return the index of the added wordcode. + */ static int ecadd(wordcode c) @@ -402,6 +417,7 @@ ecstrcode(char *s) unsigned val = hasher(s); if ((l = strlen(s) + 1) && l <= 4) { + /* Short string. */ t = has_token(s); wordcode c = (t ? 3 : 2); switch (l) { @@ -412,11 +428,13 @@ ecstrcode(char *s) } return c; } else { + /* Long string. */ Eccstr p, *pp; long cmp; for (pp = &ecstrs; (p = *pp); ) { if (!(cmp = p->nfunc - ecnfunc) && !(cmp = (((long)p->hashval) - ((long)val))) && !(cmp = strcmp(p->str, s))) { + /* Re-use the existing string. */ return p->offs; } pp = (cmp < 0 ? &(p->left) : &(p->right)); @@ -493,7 +511,12 @@ init_parse(void) /* Build eprog. */ -/* careful: copy_ecstr is from arg1 to arg2, unlike memcpy */ +/* + * Copy the strings of s and all its descendants in the binary tree to the + * memory block p. + * + * careful: copy_ecstr is from arg1 to arg2, unlike memcpy + */ static void copy_ecstr(Eccstr s, char *p) diff --git a/Src/zsh.h b/Src/zsh.h index 834142895..82d152bb8 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -832,13 +832,33 @@ struct estate { char *strs; /* strings from prog */ }; +/* + * A binary tree of strings. + * + * Refer to the "Word code." comment at the top of Src/parse.c for details. + */ typedef struct eccstr *Eccstr; - struct eccstr { + /* Child pointers. */ Eccstr left, right; + + /* String; pointer into to estate::strs. */ char *str; - wordcode offs, aoffs; + + /* Wordcode of a long string, as described in the Src/parse.c comment. */ + wordcode offs; + + /* Raw memory offset of str in estate::strs. */ + wordcode aoffs; + + /* + * ### The number of starts and ends of function definitions up to this point. + * + * String reuse may only happen between strings that have the same "nfunc" value. + */ int nfunc; + + /* Hash of str. */ int hashval; }; |