From: ceriel Date: Tue, 17 Mar 1987 22:31:43 +0000 (+0000) Subject: improved storage allocation X-Git-Tag: release-5-5~4376 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=78303cdc07c20ba199edf4fbe3fe6964f4f00f02;p=ack.git improved storage allocation --- diff --git a/util/cpp/LLlex.c b/util/cpp/LLlex.c index bb8ffa2ef..5ff8567f4 100644 --- a/util/cpp/LLlex.c +++ b/util/cpp/LLlex.c @@ -186,7 +186,7 @@ go_on: ptok->tk_val = 0; return ptok->tk_symb = INTEGER; } - ptok->tk_str = Malloc(idfsize + 1); + ptok->tk_str = Malloc(tg - buf); strcpy(ptok->tk_str, buf); return ptok->tk_symb = IDENTIFIER; } @@ -290,7 +290,7 @@ string_token(nm, stop_char) char *nm; { register int c; - register int str_size; + register unsigned int str_size; register char *str = Malloc(str_size = ISTRSIZE); register int pos = 0; @@ -316,7 +316,7 @@ string_token(nm, stop_char) } str[pos++] = c; if (pos == str_size) - str = Srealloc(str, str_size += RSTRSIZE); + str = Srealloc(str, str_size <<= 1); LoadChar(c); } str[pos++] = '\0'; /* for filenames etc. */ diff --git a/util/cpp/Parameters b/util/cpp/Parameters index f949a5624..a67a0d065 100644 --- a/util/cpp/Parameters +++ b/util/cpp/Parameters @@ -33,10 +33,8 @@ !File: strsize.h -#define ISTRSIZE 32 /* minimum number of bytes allocated for +#define ISTRSIZE 16 /* minimum number of bytes allocated for storing a string */ -#define RSTRSIZE 32 /* step size in enlarging the memory for - the storage of a string */ !File: botch_free.h @@ -52,8 +50,7 @@ !File: textsize.h -#define ITEXTSIZE 64 /* 1st piece of memory for repl. text */ -#define RTEXTSIZE 64 /* stepsize for enlarging repl.text */ +#define ITEXTSIZE 16 /* 1st piece of memory for repl. text */ !File: inputtype.h diff --git a/util/cpp/domacro.c b/util/cpp/domacro.c index 82866271d..8a5cf0019 100644 --- a/util/cpp/domacro.c +++ b/util/cpp/domacro.c @@ -586,9 +586,9 @@ get_text(formals, length) parameter. Other tokens will not be seen as such. */ register int c; - register int text_size; + register unsigned int text_size; char *text = Malloc(text_size = ITEXTSIZE); - register int pos = 0; + register unsigned int pos = 0; LoadChar(c); @@ -607,7 +607,7 @@ get_text(formals, length) else text[pos++] = '\\'; if (pos == text_size) - text = Srealloc(text, text_size += RTEXTSIZE); + text = Srealloc(text, text_size <<= 1); } else if ( c == '/') { @@ -620,43 +620,45 @@ get_text(formals, length) else text[pos++] = '/'; if (pos == text_size) - text = Srealloc(text, text_size += RTEXTSIZE); + text = Srealloc(text, text_size <<= 1); } else if (formals && class(c) == STIDF) { char id_buf[IDFSIZE + 1]; - register id_size = 0; - register n; + register char *idp = id_buf; + int n; /* read identifier: it may be a formal parameter */ - id_buf[id_size++] = c; + *idp++ = c; do { LoadChar(c); - if (id_size <= IDFSIZE) - id_buf[id_size++] = c; + if (idp <= &id_buf[IDFSIZE]) + *idp++ = c; } while (in_idf(c)); - id_buf[--id_size] = '\0'; + *--idp = '\0'; if (n = find_name(id_buf, formals)) { /* construct the formal parameter mark */ text[pos++] = FORMALP | (char) n; if (pos == text_size) text = Srealloc(text, - text_size += RTEXTSIZE); + text_size <<= 1); } else { - register char *ptr = &id_buf[0]; + int sz = idp - id_buf; - while (pos + id_size >= text_size) + idp = id_buf; + + while (pos + sz >= text_size) text = Srealloc(text, - text_size += RTEXTSIZE); - while (text[pos++] = *ptr++) ; + text_size <<= 1); + while (text[pos++] = *idp++) ; pos--; } } else { text[pos++] = c; if (pos == text_size) - text = Srealloc(text, text_size += RTEXTSIZE); + text = Srealloc(text, text_size <<= 1); LoadChar(c); } } diff --git a/util/cpp/replace.c b/util/cpp/replace.c index 47412bb6b..ce5941c85 100644 --- a/util/cpp/replace.c +++ b/util/cpp/replace.c @@ -157,7 +157,7 @@ macro2buffer(idef, actpars, siztext) If there are no parameters, this function behaves the same as strcpy(). */ - register int size = idef->id_macro->mc_length + ITEXTSIZE; + register unsigned int size = idef->id_macro->mc_length + ITEXTSIZE; register char *text = Malloc(size); register int pos = 0; register char *ptr = idef->id_macro->mc_text; @@ -174,13 +174,13 @@ macro2buffer(idef, actpars, siztext) for (p = actpars[n - 1]; *p; p++) { text[pos++] = *p; if (pos == size) - text = Srealloc(text, size += RTEXTSIZE); + text = Srealloc(text, size <<= 1); } } else { text[pos++] = *ptr++; if (pos == size) - text = Srealloc(text, size += RTEXTSIZE); + text = Srealloc(text, size <<= 1); } } text[pos] = '\0';