perl 4.0 patch 14: patch #11, continued
[p5sagit/p5-mst-13.2.git] / array.c
diff --git a/array.c b/array.c
index 6875d28..e2561d7 100644 (file)
--- a/array.c
+++ b/array.c
@@ -1,13 +1,16 @@
-/* $Header: array.c,v 3.0 89/10/18 15:08:33 lwall Locked $
+/* $RCSfile: array.c,v $$Revision: 4.0.1.1 $$Date: 91/06/07 10:19:08 $
  *
- *    Copyright (c) 1989, Larry Wall
+ *    Copyright (c) 1991, Larry Wall
  *
- *    You may distribute under the terms of the GNU General Public License
- *    as specified in the README file that comes with the perl 3.0 kit.
+ *    You may distribute under the terms of either the GNU General Public
+ *    License or the Artistic License, as specified in the README file.
  *
  * $Log:       array.c,v $
- * Revision 3.0  89/10/18  15:08:33  lwall
- * 3.0 baseline
+ * Revision 4.0.1.1  91/06/07  10:19:08  lwall
+ * patch4: new copyright notice
+ * 
+ * Revision 4.0  91/03/20  01:03:32  lwall
+ * 4.0 baseline.
  * 
  */
 
@@ -27,17 +30,20 @@ int lval;
            if (ar->ary_flags & ARF_REAL)
                str = Str_new(5,0);
            else
-               str = str_static(&str_undef);
+               str = str_mortal(&str_undef);
            (void)astore(ar,key,str);
            return str;
        }
        else
-           return Nullstr;
+           return &str_undef;
     }
-    if (lval && !ar->ary_array[key]) {
-       str = Str_new(6,0);
-       (void)astore(ar,key,str);
-       return str;
+    if (!ar->ary_array[key]) {
+       if (lval) {
+           str = Str_new(6,0);
+           (void)astore(ar,key,str);
+           return str;
+       }
+       return &str_undef;
     }
     return ar->ary_array[key];
 }
@@ -67,10 +73,16 @@ STR *val;
            }
        }
        else {
-           newmax = key + ar->ary_max / 5;
-         resize:
-           Renew(ar->ary_alloc,newmax+1, STR*);
-           Zero(&ar->ary_alloc[ar->ary_max+1], newmax - ar->ary_max, STR*);
+           if (ar->ary_alloc) {
+               newmax = key + ar->ary_max / 5;
+             resize:
+               Renew(ar->ary_alloc,newmax+1, STR*);
+               Zero(&ar->ary_alloc[ar->ary_max+1], newmax - ar->ary_max, STR*);
+           }
+           else {
+               newmax = key < 4 ? 4 : key;
+               Newz(2,ar->ary_alloc, newmax+1, STR*);
+           }
            ar->ary_array = ar->ary_alloc;
            ar->ary_max = newmax;
        }
@@ -97,13 +109,10 @@ STAB *stab;
     register ARRAY *ar;
 
     New(1,ar,1,ARRAY);
-    Newz(2,ar->ary_alloc,5,STR*);
-    ar->ary_array = ar->ary_alloc;
     ar->ary_magic = Str_new(7,0);
+    ar->ary_alloc = ar->ary_array = 0;
     str_magic(ar->ary_magic, stab, '#', Nullch, 0);
-    ar->ary_fill = -1;
-    ar->ary_index = -1;
-    ar->ary_max = 4;
+    ar->ary_max = ar->ary_fill = -1;
     ar->ary_flags = ARF_REAL;
     return ar;
 }
@@ -111,8 +120,8 @@ STAB *stab;
 ARRAY *
 afake(stab,size,strp)
 STAB *stab;
-int size;
-STR **strp;
+register int size;
+register STR **strp;
 {
     register ARRAY *ar;
 
@@ -123,9 +132,11 @@ STR **strp;
     ar->ary_magic = Str_new(8,0);
     str_magic(ar->ary_magic, stab, '#', Nullch, 0);
     ar->ary_fill = size - 1;
-    ar->ary_index = -1;
     ar->ary_max = size - 1;
     ar->ary_flags = 0;
+    while (size--) {
+       (*strp++)->str_pok &= ~SP_TEMP;
+    }
     return ar;
 }
 
@@ -135,7 +146,7 @@ register ARRAY *ar;
 {
     register int key;
 
-    if (!ar || !(ar->ary_flags & ARF_REAL))
+    if (!ar || !(ar->ary_flags & ARF_REAL) || ar->ary_max < 0)
        return;
     if (key = ar->ary_array - ar->ary_alloc) {
        ar->ary_max += key;
@@ -208,8 +219,14 @@ register int num;
        (void)astore(ar,ar->ary_fill+num,(STR*)0);      /* maybe extend array */
        dstr = ar->ary_array + ar->ary_fill;
        sstr = dstr - num;
+#ifdef BUGGY_MSC5
+ # pragma loop_opt(off)        /* don't loop-optimize the following code */
+#endif /* BUGGY_MSC5 */
        for (i = ar->ary_fill; i >= 0; i--) {
            *dstr-- = *sstr--;
+#ifdef BUGGY_MSC5
+ # pragma loop_opt()   /* loop-optimization back to command-line setting */
+#endif /* BUGGY_MSC5 */
        }
        Zero(ar->ary_array, num, STR*);
     }