src/string.c

changeset 1125
6090c455b8df
parent 1074
e8e2813cdda6
equal deleted inserted replaced
1124:fcd5d86c472f 1125:6090c455b8df
293 // local prefix table 293 // local prefix table
294 size_t s_prefix_table[CX_STRSTR_SBO_SIZE]; 294 size_t s_prefix_table[CX_STRSTR_SBO_SIZE];
295 295
296 // check needle length and use appropriate prefix table 296 // check needle length and use appropriate prefix table
297 // if the pattern exceeds static prefix table, allocate on the heap 297 // if the pattern exceeds static prefix table, allocate on the heap
298 bool useheap = needle.length >= CX_STRSTR_SBO_SIZE; 298 const bool useheap = needle.length >= CX_STRSTR_SBO_SIZE;
299 register size_t *ptable = useheap ? calloc(needle.length + 1, 299 register size_t *ptable = useheap ? calloc(needle.length + 1,
300 sizeof(size_t)) : s_prefix_table; 300 sizeof(size_t)) : s_prefix_table;
301 301
302 // keep counter in registers 302 // keep counter in registers
303 register size_t i, j; 303 register size_t i, j;
332 break; 332 break;
333 } 333 }
334 } 334 }
335 335
336 // if prefix table was allocated on the heap, free it 336 // if prefix table was allocated on the heap, free it
337 if (ptable != s_prefix_table) { 337 if (useheap) {
338 free(ptable); 338 free(ptable);
339 } 339 }
340 340
341 return result; 341 return result;
342 } 342 }

mercurial