3 ms·
It's pretty. I like the tail call. Sadly jumping over the initialisation of map then calling a function on it can't work, plus the leak. Maybe introducing canno
by JonChesterfield 3y ago
It's pretty. I like the tail call. Sadly jumping over the initialisation of map then calling a function on it can't work, plus the leak. Maybe introducing cannot-fail default constructors is the way to go, allowing something like:
intstack_t stack = intstack_default();
intmap_t map = intmap_default();
regex_compare_t res = regex_out_of_memory;
stack = intstack_create(256);
if (!intstack_valid(stack)) goto out_of_memory;
map = intmap_create(16);
if (!intmap_valid(map)) goto out_of_memory;
res = regex_canonical_equivalent_with_structures(cache, x, y, &stack, &map);
out_of_memory:
intstack_destroy(stack);
intmap_destroy(map);
return res;
It should be possible to structure things so one doesn't accumulate stack frames and also keeps the resource logic separate from the implementation but it's not immediately obvious to me what a pretty way to do that is.