mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-25 23:03:09 +02:00
119 lines
2.7 KiB
Plaintext
119 lines
2.7 KiB
Plaintext
*** array.c 2009-03-29 17:21:09.000000000 -0400
|
|
--- array.c.save3 2009-03-28 18:16:49.000000000 -0400
|
|
***************
|
|
*** 56,59 ****
|
|
--- 56,84 ----
|
|
static char *array_to_string_internal __P((ARRAY_ELEMENT *, ARRAY_ELEMENT *, char *, int));
|
|
|
|
+ static ARRAY *lastarray = 0;
|
|
+ static ARRAY_ELEMENT *lastref = 0;
|
|
+
|
|
+ #define IS_LASTREF(a) ((a) == lastarray)
|
|
+
|
|
+ #define INVALIDATE_LASTREF(a) \
|
|
+ do { \
|
|
+ if ((a) == lastarray) { \
|
|
+ lastarray = 0; \
|
|
+ lastref = 0; \
|
|
+ } \
|
|
+ } while (0)
|
|
+
|
|
+ #define SET_LASTREF(a, e) \
|
|
+ do { \
|
|
+ lastarray = (a); \
|
|
+ lastref = (e); \
|
|
+ } while (0)
|
|
+
|
|
+ #define UNSET_LASTREF() \
|
|
+ do { \
|
|
+ lastarray = 0; \
|
|
+ lastref = 0; \
|
|
+ } while (0)
|
|
+
|
|
ARRAY *
|
|
array_create()
|
|
***************
|
|
*** 88,91 ****
|
|
--- 113,117 ----
|
|
a->max_index = -1;
|
|
a->num_elements = 0;
|
|
+ INVALIDATE_LASTREF(a);
|
|
}
|
|
|
|
***************
|
|
*** 186,189 ****
|
|
--- 212,216 ----
|
|
return ((ARRAY_ELEMENT *)NULL);
|
|
|
|
+ INVALIDATE_LASTREF(a);
|
|
for (i = 0, ret = ae = element_forw(a->head); ae != a->head && i < n; ae = element_forw(ae), i++)
|
|
;
|
|
***************
|
|
*** 264,267 ****
|
|
--- 291,295 ----
|
|
a->max_index = element_index(a->head->prev);
|
|
|
|
+ INVALIDATE_LASTREF(a);
|
|
return (a->num_elements);
|
|
}
|
|
***************
|
|
*** 595,598 ****
|
|
--- 623,627 ----
|
|
a->max_index = i;
|
|
a->num_elements++;
|
|
+ SET_LASTREF(a, new);
|
|
return(0);
|
|
}
|
|
***************
|
|
*** 608,618 ****
|
|
--- 637,650 ----
|
|
free(element_value(ae));
|
|
ae->value = v ? savestring(v) : (char *)NULL;
|
|
+ SET_LASTREF(a, ae);
|
|
return(0);
|
|
} else if (element_index(ae) > i) {
|
|
ADD_BEFORE(ae, new);
|
|
a->num_elements++;
|
|
+ SET_LASTREF(a, new);
|
|
return(0);
|
|
}
|
|
}
|
|
+ INVALIDATE_LASTREF(a);
|
|
return (-1); /* problem */
|
|
}
|
|
***************
|
|
*** 638,641 ****
|
|
--- 670,674 ----
|
|
if (i == array_max_index(a))
|
|
a->max_index = element_index(ae->prev);
|
|
+ INVALIDATE_LASTREF(a);
|
|
return(ae);
|
|
}
|
|
***************
|
|
*** 655,661 ****
|
|
if (a == 0 || array_empty(a))
|
|
return((char *) NULL);
|
|
! for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae))
|
|
! if (element_index(ae) == i)
|
|
return(element_value(ae));
|
|
return((char *) NULL);
|
|
}
|
|
--- 688,704 ----
|
|
if (a == 0 || array_empty(a))
|
|
return((char *) NULL);
|
|
! if (i > array_max_index(a))
|
|
! return ((char *)NULL);
|
|
! /* Keep roving pointer into array to optimize sequential access */
|
|
! if (lastref && IS_LASTREF(a))
|
|
! ae = (i >= element_index(lastref)) ? lastref : element_forw(a->head);
|
|
! else
|
|
! ae = element_forw(a->head);
|
|
! for ( ; ae != a->head; ae = element_forw(ae))
|
|
! if (element_index(ae) == i) {
|
|
! SET_LASTREF(a, ae);
|
|
return(element_value(ae));
|
|
+ }
|
|
+ UNSET_LASTREF();
|
|
return((char *) NULL);
|
|
}
|