This makes the code way more readable, and also avoids a lot of strcmps.
Use it for draw_align_get_from_str as a proof of concept.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Make area_t smaller so that it fits in an uint64_t using 4 {u,}int16_t's
for it. Note that xcb uses the very same structure, so we aren't loosing
any information while remaining very small.
This is better to use arrays in term of:
* memory access when iterating over area_t's;
* allocation because area_t's have no *next/*prev members anymore, which
makes it a tiny structure (8 octets);
* allocation because we allocate area_t's by vector of'em rather than one
by one.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
For that matter, use elements as a filter for elements we care about, and
let the hook implement whatever it needs without duplicating everything.
The resulting algorithm is still O(n²) where n is the number of filtered
elements (3 at most right now), which isn't bad if we don't need to get
too many elements, but at least it's not quadratic in the number of
attributes anymore.
Speedup improvements could be done using gperf btw.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Do not preemptively allocate a g_markup_escape_text for substitutions,
just remember what we want to substitute markup with, and substitute it in
the final buffer efficiently.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
We have a stack, don't be ashamed to use it.
Instead of:
foo_t *foo;
foo = foo_new();
/* work with foo */
foo_delete(&foo);
It's way better to:
foo_t foo;
foo_init(&foo);
/* work with &foo */
foo_wipe(&foo);
Remember: more mallocs == more fragmentation.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
put *item to NULL on unref, as we cannot know if the pointer is valid
after an unref, so just segfault rather than hide a problem.
Also return *item on ref() it allow short versions like:
foo_list_push(&list, foo_ref(&elem));
which is kind of readable _and_ handy.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>