diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-10-06 20:43:58 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-10-06 20:43:58 -0700 |
commit | c126cf0d1e737c3eaad9fedf16071a397dcf3aad (patch) | |
tree | d5bf5dc9532579ee3df618b1ec9df3e089a371b3 /configure | |
parent | 6fd2b82e5e6ae996c4339a4d53307dd9610fe70d (diff) | |
download | txr-c126cf0d1e737c3eaad9fedf16071a397dcf3aad.tar.gz txr-c126cf0d1e737c3eaad9fedf16071a397dcf3aad.tar.bz2 txr-c126cf0d1e737c3eaad9fedf16071a397dcf3aad.zip |
strings: take advantage of malloc_usable_size
On platforms which have the malloc_usable_size function,
we don't have to store the allocated size of an object;
malloc provides us the allocated size (which may be larger
than we requested). Here we take advantage of this for
strings. And since we don't have to store the string
allocated size any more, we use that field for something
else: storing the hash code (for seed zero). This can speed
up some hashing operations.
* configure (have_malloc_usable_size): New variable.
Configure test for have_malloc_usable size. We have to
try several header files, too. We set the configure
variable HAVE_MALLOC_USABLE_SIZE, and possibly
HAVE_MALLOC_H or HAVE_MALLOC_NP_H.
* lib.h (struct string): If HAVE_MALLOC_USABLE_SIZE
is true, we define a member called hash insetad of
alloc. Also, we change alloc to cnum.
* lib.c: Include <malloc_np.h> if HAVE_MALLOC_NP_H
is defined.
(string_own, string, string_utf8, mkstring, mkustring,
init_str, string_extend, string_finish, string_set_code,
string_get_code, length_str, replace_str, chr_str_set):
Fix code for both cases. On platforms with malloc_usable_size,
we have the allocated size from malloc, so we don't have to
retrieve it from the object or store it. Any operations which
mutate the string must reset the hash field to zero; zero
means "hash has not been calculated".
* hash.c (equal_hash): Just retrive a string's hash value, if
it is nonzero, otherwise calculate, cache it and return it.
* gc.c (mark_obj): The alloc member of struct string is a
machine integer now; no need to mark it.
Diffstat (limited to 'configure')
-rwxr-xr-x | configure | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -214,6 +214,7 @@ have_termios= have_winsize= termios_define= have_pkgconfig= +have_malloc_usable_size= libffi_cflags= darwin_target= solaris_target= @@ -3335,6 +3336,34 @@ int main(void) break done +printf "Checking for malloc_usable_size ..." + +for header in stdlib malloc malloc_np ; do + cat > conftest.c <<! +#include <$header.h> + +int main(int argc, char **argv) +{ + void *p = malloc(42); + size_t s = malloc_usable_size(p); + return 0; +} +! + + if conftest ; then + printf "yes (<%s.h>)\n" $header + printf "#define HAVE_MALLOC_USABLE_SIZE 1\n" >> config.h + if [ $header != stdlib ] ; then + header=$(printf "%s" $header | tr '[a-z]' '[A-Z]') + printf "#define HAVE_%s_H 1\n" $header >> config.h + fi + have_malloc_usable_size=y + break + fi +done + +[ "$have_malloc_usable_size" ] || printf "no\n" + printf "Checking for termios ... " cat > conftest.c <<! |