# HG changeset patch # User Mike Becker # Date 1675271210 -3600 # Node ID 5700ba9154ab37f6616e8582759f50c34040a4b2 # Parent 98c90759f69e8b574e1f19345fc8b705e4bc9c49 #228 make buffer sizes adjustable at compile time diff -r 98c90759f69e -r 5700ba9154ab src/array_list.c --- a/src/array_list.c Wed Feb 01 17:14:17 2023 +0100 +++ b/src/array_list.c Wed Feb 01 18:06:50 2023 +0100 @@ -103,7 +103,9 @@ return CX_ARRAY_COPY_SUCCESS; } +#ifndef CX_ARRAY_SWAP_SBO_SIZE #define CX_ARRAY_SWAP_SBO_SIZE 512 +#endif void cx_array_swap( void *arr, diff -r 98c90759f69e -r 5700ba9154ab src/printf.c --- a/src/printf.c Wed Feb 01 17:14:17 2023 +0100 +++ b/src/printf.c Wed Feb 01 18:06:50 2023 +0100 @@ -31,9 +31,16 @@ #include #include -#define CX_PRINTF_BUFSIZE 256 +#ifndef CX_PRINTF_SBO_SIZE +#define CX_PRINTF_SBO_SIZE 512 +#endif -int cx_fprintf(void *stream, cx_write_func wfc, char const *fmt, ...) { +int cx_fprintf( + void *stream, + cx_write_func wfc, + char const *fmt, + ... +) { int ret; va_list ap; va_start(ap, fmt); @@ -43,13 +50,13 @@ } int cx_vfprintf(void *stream, cx_write_func wfc, char const *fmt, va_list ap) { - char buf[CX_PRINTF_BUFSIZE]; + char buf[CX_PRINTF_SBO_SIZE]; va_list ap2; va_copy(ap2, ap); - int ret = vsnprintf(buf, CX_PRINTF_BUFSIZE, fmt, ap); + int ret = vsnprintf(buf, CX_PRINTF_SBO_SIZE, fmt, ap); if (ret < 0) { return ret; - } else if (ret < CX_PRINTF_BUFSIZE) { + } else if (ret < CX_PRINTF_SBO_SIZE) { return (int) wfc(buf, 1, ret, stream); } else { int len = ret + 1; @@ -80,11 +87,11 @@ cxmutstr s; s.ptr = NULL; s.length = 0; - char buf[CX_PRINTF_BUFSIZE]; + char buf[CX_PRINTF_SBO_SIZE]; va_list ap2; va_copy(ap2, ap); - int ret = vsnprintf(buf, CX_PRINTF_BUFSIZE, fmt, ap); - if (ret > 0 && ret < CX_PRINTF_BUFSIZE) { + int ret = vsnprintf(buf, CX_PRINTF_SBO_SIZE, fmt, ap); + if (ret > 0 && ret < CX_PRINTF_SBO_SIZE) { s.ptr = cxMalloc(a, ret + 1); if (s.ptr) { s.length = (size_t) ret; diff -r 98c90759f69e -r 5700ba9154ab src/string.c --- a/src/string.c Wed Feb 01 17:14:17 2023 +0100 +++ b/src/string.c Wed Feb 01 18:06:50 2023 +0100 @@ -226,7 +226,9 @@ return (cxmutstr) {(char *) result.ptr, result.length}; } -#define STRSTR_SBO_BUFLEN 512 +#ifndef CX_STRSTR_SBO_SIZE +#define CX_STRSTR_SBO_SIZE 512 +#endif cxstring cx_strstr( cxstring haystack, @@ -250,11 +252,11 @@ */ // local prefix table - size_t s_prefix_table[STRSTR_SBO_BUFLEN]; + size_t s_prefix_table[CX_STRSTR_SBO_SIZE]; // check needle length and use appropriate prefix table // if the pattern exceeds static prefix table, allocate on the heap - bool useheap = needle.length >= STRSTR_SBO_BUFLEN; + bool useheap = needle.length >= CX_STRSTR_SBO_SIZE; register size_t *ptable = useheap ? calloc(needle.length + 1, sizeof(size_t)) : s_prefix_table; @@ -539,7 +541,9 @@ } } -#define REPLACE_INDEX_BUFFER_MAX 100 +#ifndef CX_STRREPLACE_INDEX_BUFFER_SIZE +#define CX_STRREPLACE_INDEX_BUFFER_SIZE 64 +#endif struct cx_strreplace_ibuf { size_t *buf; @@ -570,8 +574,8 @@ // Compute expected buffer length size_t ibufmax = str.length / pattern.length; size_t ibuflen = replmax < ibufmax ? replmax : ibufmax; - if (ibuflen > REPLACE_INDEX_BUFFER_MAX) { - ibuflen = REPLACE_INDEX_BUFFER_MAX; + if (ibuflen > CX_STRREPLACE_INDEX_BUFFER_SIZE) { + ibuflen = CX_STRREPLACE_INDEX_BUFFER_SIZE; } // Allocate first index buffer