src/string.c

changeset 1318
12fa1d37fe48
parent 1304
57e062a4bb05
child 1319
aa1f580f8f59
equal deleted inserted replaced
1317:eeb2fc3850e2 1318:12fa1d37fe48
63 return (cxstring) {cstring, length}; 63 return (cxstring) {cstring, length};
64 } 64 }
65 65
66 void cx_strfree(cxmutstr *str) { 66 void cx_strfree(cxmutstr *str) {
67 if (str == NULL) return; 67 if (str == NULL) return;
68 free(str->ptr); 68 cxFree(cxDefaultAllocator, str->ptr);
69 str->ptr = NULL; 69 str->ptr = NULL;
70 str->length = 0; 70 str->length = 0;
71 } 71 }
72 72
73 void cx_strfree_a( 73 void cx_strfree_a(
284 size_t s_prefix_table[CX_STRSTR_SBO_SIZE]; 284 size_t s_prefix_table[CX_STRSTR_SBO_SIZE];
285 285
286 // check needle length and use appropriate prefix table 286 // check needle length and use appropriate prefix table
287 // if the pattern exceeds static prefix table, allocate on the heap 287 // if the pattern exceeds static prefix table, allocate on the heap
288 const bool useheap = needle.length >= CX_STRSTR_SBO_SIZE; 288 const bool useheap = needle.length >= CX_STRSTR_SBO_SIZE;
289 register size_t *ptable = useheap ? calloc(needle.length + 1, 289 register size_t *ptable = useheap
290 sizeof(size_t)) : s_prefix_table; 290 ? cxCalloc(cxDefaultAllocator, needle.length + 1, sizeof(size_t))
291 : s_prefix_table;
291 292
292 // keep counter in registers 293 // keep counter in registers
293 register size_t i, j; 294 register size_t i, j;
294 295
295 // fill prefix table 296 // fill prefix table
323 } 324 }
324 } 325 }
325 326
326 // if prefix table was allocated on the heap, free it 327 // if prefix table was allocated on the heap, free it
327 if (useheap) { 328 if (useheap) {
328 free(ptable); 329 cxFree(cxDefaultAllocator, ptable);
329 } 330 }
330 331
331 return result; 332 return result;
332 } 333 }
333 334

mercurial