improved storage allocation
This commit is contained in:
parent
10080ca0f2
commit
78303cdc07
4 changed files with 26 additions and 27 deletions
|
@ -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. */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in a new issue