Added high-speed clear loops and changed behaviour of Realloc

This commit is contained in:
ceriel 1990-11-01 09:32:21 +00:00
parent 8265d3f731
commit 1aef1c5921
4 changed files with 29 additions and 2 deletions

View file

@ -17,7 +17,10 @@ Realloc(ptr, sz)
char ptr[]; char ptr[];
unsigned int sz; unsigned int sz;
{ {
register char *mptr = realloc(ptr, sz); register char *mptr;
if (!ptr) mptr = malloc(sz);
else mptr = realloc(ptr, sz);
if (sz && mptr == 0) No_Mem(); if (sz && mptr == 0) No_Mem();
return mptr; return mptr;
} }

View file

@ -56,7 +56,8 @@ bytes, initialized with the null-terminated string \fIstr\fR.
.PP .PP
\fIRealloc\fR changes the size of \fIRealloc\fR changes the size of
the block at \fIbuf\fR to \fIsize\fR bytes, and returns a pointer to the the block at \fIbuf\fR to \fIsize\fR bytes, and returns a pointer to the
(possibly moved) block. (possibly moved) block. If \fIbuf\fP is a null pointer, \fIRealloc\fP
behaves as \fIMalloc\fP.
.PP .PP
\fISrealloc\fR reallocates \fISrealloc\fR reallocates
the string at \fIstr\fR to \fIsize\fR bytes. the string at \fIstr\fR to \fIsize\fR bytes.

View file

@ -13,6 +13,18 @@ clear(ptr, n)
{ {
register long *q = (long *) ptr; register long *q = (long *) ptr;
while (n >= 8*sizeof (long)) {
/* high-speed clear loop */
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
n -= 8*sizeof (long);
}
while (n >= sizeof (long)) { while (n >= sizeof (long)) {
/* high-speed clear loop */ /* high-speed clear loop */
*q++ = 0; *q++ = 0;

View file

@ -37,6 +37,17 @@ st_alloc(phead, size, count)
*phead = (char *) (((_PALLOC_)p)->_A_next); *phead = (char *) (((_PALLOC_)p)->_A_next);
retval = p; retval = p;
q = (long *) p; q = (long *) p;
while (size >= 8*sizeof(long)) {
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
*q++ = 0;
size -= 8*sizeof(long);
}
while (size >= sizeof(long)) { while (size >= sizeof(long)) {
*q++ = 0; *q++ = 0;
size -= sizeof(long); size -= sizeof(long);