Append characters at the current key string of the defragmentation * iterator. Like the normal iterator, the key is rebuilt incrementally as * the walk descends and climbs the radix tree. */
| 2369 | * iterator. Like the normal iterator, the key is rebuilt incrementally as |
| 2370 | * the walk descends and climbs the radix tree. */ |
| 2371 | static int raxDefragAddChars(raxDefragIterator *it, unsigned char *s, |
| 2372 | size_t len) |
| 2373 | { |
| 2374 | if (len == 0) return 1; |
| 2375 | if (it->key_max < it->key_len+len) { |
| 2376 | int from_static = it->key == it->key_static_string; |
| 2377 | unsigned char *old = from_static ? NULL : it->key; |
| 2378 | size_t new_max = (it->key_len+len)*2; |
| 2379 | unsigned char *new_key = rax_realloc(old,new_max); |
| 2380 | if (new_key == NULL) { |
| 2381 | errno = ENOMEM; |
| 2382 | return 0; |
| 2383 | } |
| 2384 | it->key = new_key; |
| 2385 | if (from_static) memcpy(it->key,it->key_static_string,it->key_len); |
| 2386 | it->key_max = new_max; |
| 2387 | } |
| 2388 | memcpy(it->key+it->key_len,s,len); |
| 2389 | it->key_len += len; |
| 2390 | return 1; |
| 2391 | } |
| 2392 | |
| 2393 | /* Remove the specified number of chars from the right of the current key. */ |
| 2394 | static inline void raxDefragDelChars(raxDefragIterator *it, size_t count) { |