mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-29 00:19:51 +02:00
new alternate array implementation that prioritizes access time over sparse arrays; selectable via configure
This commit is contained in:
@@ -62,6 +62,7 @@ config-bot.h f
|
||||
config.h.in f
|
||||
aclocal.m4 f
|
||||
array.c f
|
||||
array2.c f
|
||||
arrayfunc.c f
|
||||
assoc.c f
|
||||
eval.c f
|
||||
|
||||
+11
-1
@@ -483,12 +483,14 @@ JOBS_O = @JOBS_O@
|
||||
SIGLIST_O = @SIGLIST_O@
|
||||
SIGNAMES_O = @SIGNAMES_O@
|
||||
|
||||
ARRAY_O = @ARRAY_O@
|
||||
|
||||
# Matching object files.
|
||||
OBJECTS = shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o $(GLOBO) \
|
||||
dispose_cmd.o execute_cmd.o variables.o copy_cmd.o error.o \
|
||||
expr.o flags.o $(JOBS_O) subst.o hashcmd.o hashlib.o mailcheck.o \
|
||||
trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o \
|
||||
alias.o array.o arrayfunc.o assoc.o braces.o bracecomp.o bashhist.o \
|
||||
alias.o $(ARRAY_O) arrayfunc.o assoc.o braces.o bracecomp.o bashhist.o \
|
||||
bashline.o $(SIGLIST_O) list.o stringlib.o locale.o findcmd.o redir.o \
|
||||
pcomplete.o pcomplib.o syntax.o xmalloc.o $(SIGNAMES_O)
|
||||
|
||||
@@ -995,6 +997,7 @@ hashtest: hashlib.c
|
||||
# Files that depend on the definitions in config-top.h, which are not meant
|
||||
# to be changed
|
||||
array.o: $(srcdir)/config-top.h
|
||||
array2.o: $(srcdir)/config-top.h
|
||||
bashhist.o: $(srcdir)/config-top.h
|
||||
shell.o: $(srcdir)/config-top.h
|
||||
input.o: $(srcdir)/config-top.h
|
||||
@@ -1258,6 +1261,13 @@ array.o: quit.h ${BASHINCDIR}/maxpath.h unwind_prot.h dispose_cmd.h
|
||||
array.o: make_cmd.h subst.h sig.h pathnames.h externs.h
|
||||
array.o: $(BASHINCDIR)/ocache.h $(BASHINCDIR)/chartypes.h
|
||||
array.o: $(DEFSRC)/common.h
|
||||
array2.o: config.h bashansi.h ${BASHINCDIR}/ansi_stdlib.h
|
||||
array2.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h command.h ${BASHINCDIR}/stdc.h error.h
|
||||
array2.o: general.h xmalloc.h bashtypes.h variables.h arrayfunc.h conftypes.h array.h hashlib.h
|
||||
array2.o: quit.h ${BASHINCDIR}/maxpath.h unwind_prot.h dispose_cmd.h
|
||||
array2.o: make_cmd.h subst.h sig.h pathnames.h externs.h
|
||||
array2.o: $(BASHINCDIR)/ocache.h $(BASHINCDIR)/chartypes.h
|
||||
array2.o: $(DEFSRC)/common.h
|
||||
arrayfunc.o: config.h bashansi.h ${BASHINCDIR}/ansi_stdlib.h
|
||||
arrayfunc.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h command.h ${BASHINCDIR}/stdc.h error.h
|
||||
arrayfunc.o: general.h xmalloc.h bashtypes.h variables.h arrayfunc.h conftypes.h array.h hashlib.h
|
||||
|
||||
@@ -32,27 +32,52 @@ enum atype {array_indexed, array_assoc}; /* not used */
|
||||
typedef struct array {
|
||||
arrayind_t max_index;
|
||||
arrayind_t num_elements;
|
||||
#ifdef ALT_ARRAY_IMPLEMENTATION
|
||||
arrayind_t first_index;
|
||||
arrayind_t alloc_size;
|
||||
struct array_element **elements;
|
||||
#else
|
||||
struct array_element *head;
|
||||
struct array_element *lastref;
|
||||
#endif
|
||||
} ARRAY;
|
||||
|
||||
typedef struct array_element {
|
||||
arrayind_t ind;
|
||||
char *value;
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
struct array_element *next, *prev;
|
||||
#endif
|
||||
} ARRAY_ELEMENT;
|
||||
|
||||
#define ARRAY_DEFAULT_SIZE 1024
|
||||
|
||||
typedef int sh_ae_map_func_t PARAMS((ARRAY_ELEMENT *, void *));
|
||||
|
||||
/* Basic operations on entire arrays */
|
||||
#ifdef ALT_ARRAY_IMPLEMENTATION
|
||||
extern void array_alloc PARAMS((ARRAY *, arrayind_t));
|
||||
extern void array_resize PARAMS((ARRAY *, arrayind_t));
|
||||
extern void array_expand PARAMS((ARRAY *, arrayind_t));
|
||||
extern void array_dispose_elements PARAMS((ARRAY_ELEMENT **));
|
||||
#endif
|
||||
extern ARRAY *array_create PARAMS((void));
|
||||
extern void array_flush PARAMS((ARRAY *));
|
||||
extern void array_dispose PARAMS((ARRAY *));
|
||||
extern ARRAY *array_copy PARAMS((ARRAY *));
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
extern ARRAY *array_slice PARAMS((ARRAY *, ARRAY_ELEMENT *, ARRAY_ELEMENT *));
|
||||
#else
|
||||
extern ARRAY *array_slice PARAMS((ARRAY *, arrayind_t, arrayind_t));
|
||||
#endif
|
||||
|
||||
extern void array_walk PARAMS((ARRAY *, sh_ae_map_func_t *, void *));
|
||||
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
extern ARRAY_ELEMENT *array_shift PARAMS((ARRAY *, int, int));
|
||||
#else
|
||||
extern ARRAY_ELEMENT **array_shift PARAMS((ARRAY *, int, int));
|
||||
#endif
|
||||
extern int array_rshift PARAMS((ARRAY *, int, char *));
|
||||
extern ARRAY_ELEMENT *array_unshift_element PARAMS((ARRAY *));
|
||||
extern int array_shift_element PARAMS((ARRAY *, char *));
|
||||
@@ -97,17 +122,34 @@ extern ARRAY *array_from_string PARAMS((char *, char *));
|
||||
|
||||
#define array_num_elements(a) ((a)->num_elements)
|
||||
#define array_max_index(a) ((a)->max_index)
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
#define array_first_index(a) ((a)->head->next->ind)
|
||||
#define array_head(a) ((a)->head)
|
||||
#define array_alloc_size(a) ((a)->alloc_size)
|
||||
#else
|
||||
#define array_first_index(a) ((a)->first_index)
|
||||
#define array_head(a) ((a)->elements)
|
||||
#endif
|
||||
#define array_empty(a) ((a)->num_elements == 0)
|
||||
|
||||
#define element_value(ae) ((ae)->value)
|
||||
#define element_index(ae) ((ae)->ind)
|
||||
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
#define element_forw(ae) ((ae)->next)
|
||||
#define element_back(ae) ((ae)->prev)
|
||||
#else
|
||||
extern arrayind_t element_forw PARAMS((ARRAY *, arrayind_t));
|
||||
extern arrayind_t element_back PARAMS((ARRAY *, arrayind_t));
|
||||
#endif
|
||||
|
||||
|
||||
#define set_element_value(ae, val) ((ae)->value = (val))
|
||||
|
||||
#ifdef ALT_ARRAY_IMPLEMENTATION
|
||||
#define set_first_index(a, i) ((a)->first_index = (i))
|
||||
#endif
|
||||
|
||||
#define set_max_index(a, i) ((a)->max_index = (i))
|
||||
#define set_num_elements(a, n) ((a)->num_elements = (n))
|
||||
|
||||
@@ -129,6 +171,11 @@ extern ARRAY *array_from_string PARAMS((char *, char *));
|
||||
(ae)->value = (v); \
|
||||
} while (0)
|
||||
|
||||
#ifdef ALT_ARRAY_IMPLEMENTATION
|
||||
#define ARRAY_VALUE_REPLACE(a, i, v) \
|
||||
ARRAY_ELEMENT_REPLACE((a)->elements[(i)], (v))
|
||||
#endif
|
||||
|
||||
#define ALL_ELEMENT_SUB(c) ((c) == '@' || (c) == '*')
|
||||
|
||||
/* In eval.c, but uses ARRAY * */
|
||||
|
||||
@@ -1157,6 +1157,8 @@
|
||||
|
||||
#undef DEV_FD_STAT_BROKEN
|
||||
|
||||
/* An array implementation that prioritizes speed (O(1) access) over space,
|
||||
in array2.c */
|
||||
#undef ALT_ARRAY_IMPLEMENTATION
|
||||
|
||||
/* Additional defines for configuring lib/intl, maintained by autoscan/autoheader */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /bin/sh
|
||||
# From configure.ac for Bash 5.1, version 5.033.
|
||||
# From configure.ac for Bash 5.1, version 5.034.
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.71 for bash 5.1-maint.
|
||||
#
|
||||
@@ -782,6 +782,7 @@ HELPFILES_TARGET
|
||||
HELPINSTALL
|
||||
HELPDIRDEFINE
|
||||
HELPDIR
|
||||
ARRAY_O
|
||||
MALLOC_DEP
|
||||
MALLOC_LDFLAGS
|
||||
MALLOC_LIBRARY
|
||||
@@ -3411,6 +3412,8 @@ opt_function_import=yes
|
||||
opt_dev_fd_stat_broken=no
|
||||
opt_alt_array_impl=no
|
||||
|
||||
ARRAY_O=array.o
|
||||
|
||||
opt_static_link=no
|
||||
opt_profiling=no
|
||||
|
||||
@@ -3818,6 +3821,7 @@ fi
|
||||
if test $opt_alt_array_impl = yes; then
|
||||
printf "%s\n" "#define ALT_ARRAY_IMPLEMENTATION 1" >>confdefs.h
|
||||
|
||||
ARRAY_O=array2.o
|
||||
fi
|
||||
|
||||
if test $opt_memscramble = yes; then
|
||||
@@ -3864,6 +3868,8 @@ fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if test -z "$CFLAGS"; then
|
||||
want_auto_cflags=1
|
||||
fi
|
||||
|
||||
+7
-1
@@ -21,7 +21,7 @@ dnl Process this file with autoconf to produce a configure script.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
AC_REVISION([for Bash 5.1, version 5.033])dnl
|
||||
AC_REVISION([for Bash 5.1, version 5.034])dnl
|
||||
|
||||
define(bashvers, 5.1)
|
||||
define(relstatus, maint)
|
||||
@@ -184,6 +184,9 @@ opt_function_import=yes
|
||||
opt_dev_fd_stat_broken=no
|
||||
opt_alt_array_impl=no
|
||||
|
||||
dnl modified by alternate array implementation option
|
||||
ARRAY_O=array.o
|
||||
|
||||
dnl options that affect how bash is compiled and linked
|
||||
opt_static_link=no
|
||||
opt_profiling=no
|
||||
@@ -358,6 +361,7 @@ AC_DEFINE(DEV_FD_STAT_BROKEN)
|
||||
fi
|
||||
if test $opt_alt_array_impl = yes; then
|
||||
AC_DEFINE(ALT_ARRAY_IMPLEMENTATION)
|
||||
ARRAY_O=array2.o
|
||||
fi
|
||||
|
||||
if test $opt_memscramble = yes; then
|
||||
@@ -396,6 +400,8 @@ AC_SUBST(MALLOC_LIBRARY)
|
||||
AC_SUBST(MALLOC_LDFLAGS)
|
||||
AC_SUBST(MALLOC_DEP)
|
||||
|
||||
AC_SUBST(ARRAY_O)
|
||||
|
||||
AC_SUBST(htmldir)
|
||||
|
||||
AC_SUBST(HELPDIR)
|
||||
|
||||
+29
@@ -6291,16 +6291,26 @@ set_pipestatus_array (ps, nproc)
|
||||
/* Fast case */
|
||||
if (array_num_elements (a) == nproc && nproc == 1)
|
||||
{
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
ae = element_forw (a->head);
|
||||
#else
|
||||
ae = a->elements[0];
|
||||
#endif
|
||||
ARRAY_ELEMENT_REPLACE (ae, itos (ps[0]));
|
||||
}
|
||||
else if (array_num_elements (a) <= nproc)
|
||||
{
|
||||
/* modify in array_num_elements members in place, then add */
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
ae = a->head;
|
||||
#endif
|
||||
for (i = 0; i < array_num_elements (a); i++)
|
||||
{
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
ae = element_forw (ae);
|
||||
#else
|
||||
ae = a->elements[i];
|
||||
#endif
|
||||
ARRAY_ELEMENT_REPLACE (ae, itos (ps[i]));
|
||||
}
|
||||
/* add any more */
|
||||
@@ -6312,6 +6322,7 @@ set_pipestatus_array (ps, nproc)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
/* deleting elements. it's faster to rebuild the array. */
|
||||
array_flush (a);
|
||||
for (i = 0; i < nproc; i++)
|
||||
@@ -6319,6 +6330,24 @@ set_pipestatus_array (ps, nproc)
|
||||
t = inttostr (ps[i], tbuf, sizeof (tbuf));
|
||||
array_insert (a, i, t);
|
||||
}
|
||||
#else
|
||||
/* deleting elements. replace the first NPROC, free the rest */
|
||||
for (i = 0; i < nproc; i++)
|
||||
{
|
||||
ae = a->elements[i];
|
||||
ARRAY_ELEMENT_REPLACE (ae, itos (ps[i]));
|
||||
}
|
||||
for ( ; i <= array_max_index (a); i++)
|
||||
{
|
||||
array_dispose_element (a->elements[i]);
|
||||
a->elements[i] = (ARRAY_ELEMENT *)NULL;
|
||||
}
|
||||
|
||||
/* bookkeeping usually taken care of by array_insert */
|
||||
set_max_index (a, nproc - 1);
|
||||
set_first_index (a, 0);
|
||||
set_num_elements (a, nproc);
|
||||
#endif /* ALT_ARRAY_IMPLEMENTATION */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user