Added high-speed clear loops and changed behaviour of Realloc
authorceriel <none@none>
Thu, 1 Nov 1990 09:32:21 +0000 (09:32 +0000)
committerceriel <none@none>
Thu, 1 Nov 1990 09:32:21 +0000 (09:32 +0000)
modules/src/alloc/Realloc.c
modules/src/alloc/alloc.3
modules/src/alloc/clear.c
modules/src/alloc/st_alloc.c

index 527b526..76e24d9 100644 (file)
@@ -17,7 +17,10 @@ Realloc(ptr, sz)
        char ptr[];
        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();
        return mptr;
 }
index b79d270..31d0cd9 100644 (file)
@@ -56,7 +56,8 @@ bytes, initialized with the null-terminated string \fIstr\fR.
 .PP
 \fIRealloc\fR changes the size of
 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
 \fISrealloc\fR reallocates
 the string at \fIstr\fR to \fIsize\fR bytes.
index d6bce42..996af53 100644 (file)
@@ -13,6 +13,18 @@ clear(ptr, n)
 {
        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))      {
                        /* high-speed clear loop */
                *q++ = 0;
index b8c6927..ad469df 100644 (file)
@@ -37,6 +37,17 @@ st_alloc(phead, size, count)
        *phead = (char *) (((_PALLOC_)p)->_A_next);
        retval = 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)) {
                *q++ = 0;
                size -= sizeof(long);