From 6eb174cb138dc9c4bdd92d27a5b30ff03881db63 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 29 Jan 2025 06:28:48 -0800 Subject: build: remove HAVE_MALLOC_USABLE_SIZE. The malloc_usable_size use in the STR type actually makes operations like string_extend substantially slower. It is faster to store the allocated size locally. Originally, on platforms that have malloc_usable_size, we were able to use the word of memory reclaimed from the string type to store a cached hash code. But that logic was revereted in 2022, so there is no such benefit. * configure (have_malloc_usable_size): Variable removed. Test for the malloc_usable_size function removed. (HAVE_MALLOC_USABLE_SIZE, HAVE_MALLOC_NP): Do not define these preprocessor symbols. * lib.c (HAVE_MALLOC_NP_H): Do not test for this variale to include (string-own, string, string_utf8, mkstring, mkustring, string_extend, string_finish, string_set_code, string_get_code, length_str): Eliminate #ifdefs on HAVE_MALLOC_USABLE_SIZE. * lib.h (struct wstring): Eliminate #ifdef on MALLOC_USABLE_SIZE, so alloc member is unconditionally defined on all platforms. --- configure | 29 ----------------------------- lib.c | 35 ----------------------------------- lib.h | 2 -- 3 files changed, 66 deletions(-) diff --git a/configure b/configure index 43518736..34fafe37 100755 --- a/configure +++ b/configure @@ -214,7 +214,6 @@ have_termios= have_winsize= termios_define= have_pkgconfig= -have_malloc_usable_size= libffi_cflags= darwin_target= solaris_target= @@ -3418,34 +3417,6 @@ int main(void) break done -printf "Checking for malloc_usable_size ... " - -for header in stdlib malloc malloc_np ; do - cat > conftest.c < - -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 < #endif -#if HAVE_MALLOC_NP_H -#include -#endif #include "lib.h" #include "gc.h" #include "arith.h" @@ -5238,9 +5235,7 @@ val string_own(wchar_t *str) obj->st.type = STR; obj->st.str = str; obj->st.len = nil; -#if !HAVE_MALLOC_USABLE_SIZE obj->st.alloc = 0; -#endif return obj; } @@ -5250,9 +5245,7 @@ val string(const wchar_t *str) obj->st.type = STR; obj->st.str = chk_strdup(str); obj->st.len = nil; -#if !HAVE_MALLOC_USABLE_SIZE obj->st.alloc = 0; -#endif return obj; } @@ -5262,9 +5255,7 @@ val string_utf8(const char *str) obj->st.type = STR; obj->st.str = utf8_dup_from(str); obj->st.len = nil; -#if !HAVE_MALLOC_USABLE_SIZE obj->st.alloc = 0; -#endif return obj; } @@ -5300,9 +5291,7 @@ val mkstring(val len, val ch_in) wmemset(str, c_chr(ch), l); str[l] = 0; s->st.len = len; -#if !HAVE_MALLOC_USABLE_SIZE s->st.alloc = c_num(len, self) + 1; -#endif return s; } @@ -5317,9 +5306,7 @@ val mkustring(val len) val s = string_own(str); str[l] = 0; s->st.len = len; -#if !HAVE_MALLOC_USABLE_SIZE s->st.alloc = c_num(len, self) + 1; -#endif return s; } @@ -5408,11 +5395,7 @@ val string_extend(val str, val tail, val finish_in) { val finish = default_null_arg(finish_in); cnum len = c_fixnum(length_str(str), self); -#if HAVE_MALLOC_USABLE_SIZE - cnum oalloc = malloc_usable_size(str->st.str) / sizeof str->st.str[0]; -#else cnum oalloc = str->st.alloc; -#endif cnum alloc = oalloc, delta, needed; if (stringp(tail)) @@ -5439,9 +5422,7 @@ val string_extend(val str, val tail, val finish_in) if (alloc != oalloc) { str->st.str = chk_wrealloc(str->st.str, alloc); -#if !HAVE_MALLOC_USABLE_SIZE str->st.alloc = alloc; -#endif } } @@ -5465,18 +5446,12 @@ val string_finish(val str) { cnum len = c_fixnum(length_str(str), self); -#if HAVE_MALLOC_USABLE_SIZE - cnum alloc = malloc_usable_size(str->st.str) / sizeof str->st.str[0]; -#else cnum alloc = str->st.alloc; -#endif if (alloc > len + 1) { alloc = len + 1; str->st.str = chk_wrealloc(str->st.str, alloc); -#if !HAVE_MALLOC_USABLE_SIZE str->st.alloc = alloc; -#endif } } @@ -5490,11 +5465,7 @@ val string_set_code(val str, val code) { cnum len = c_fixnum(length_str(str), self); -#if HAVE_MALLOC_USABLE_SIZE - cnum alloc = malloc_usable_size(str->st.str) / sizeof str->st.str[0]; -#else cnum alloc = str->st.alloc; -#endif if (alloc < len + 2) { string_extend(str, one, t); @@ -5516,11 +5487,7 @@ val string_get_code(val str) { cnum len = c_fixnum(length_str(str), self); -#if HAVE_MALLOC_USABLE_SIZE - cnum alloc = malloc_usable_size(str->st.str) / sizeof str->st.str[0]; -#else cnum alloc = str->st.alloc; -#endif if (alloc >= len + 2) return num(str->st.str[len + 1]); @@ -5566,9 +5533,7 @@ val length_str(val str) case STR: if (!str->st.len) { set(mkloc(str->st.len, str), num(wcslen(str->st.str))); -#if !HAVE_MALLOC_USABLE_SIZE str->st.alloc = c_num(str->st.len, self) + 1; -#endif } return str->st.len; default: diff --git a/lib.h b/lib.h index 66246ea4..af7e6f8e 100644 --- a/lib.h +++ b/lib.h @@ -160,9 +160,7 @@ struct string { obj_common; wchar_t *str; val len; -#if !HAVE_MALLOC_USABLE_SIZE cnum alloc; -#endif }; typedef struct { -- cgit v1.2.3