avoid unnecessary comparison default tip

Tue, 14 Jan 2025 21:40:29 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 14 Jan 2025 21:40:29 +0100
changeset 1125
6090c455b8df
parent 1124
fcd5d86c472f

avoid unnecessary comparison

src/string.c file | annotate | diff | comparison | revisions
--- a/src/string.c	Sun Jan 12 13:25:50 2025 +0100
+++ b/src/string.c	Tue Jan 14 21:40:29 2025 +0100
@@ -295,7 +295,7 @@
 
     // check needle length and use appropriate prefix table
     // if the pattern exceeds static prefix table, allocate on the heap
-    bool useheap = needle.length >= CX_STRSTR_SBO_SIZE;
+    const bool useheap = needle.length >= CX_STRSTR_SBO_SIZE;
     register size_t *ptable = useheap ? calloc(needle.length + 1,
                                                sizeof(size_t)) : s_prefix_table;
 
@@ -334,7 +334,7 @@
     }
 
     // if prefix table was allocated on the heap, free it
-    if (ptable != s_prefix_table) {
+    if (useheap) {
         free(ptable);
     }
 

mercurial