Some atom related optimizations
authorRan Benita <ran234@gmail.com>
Mon, 23 Jul 2012 13:03:34 +0000 (16:03 +0300)
committerRan Benita <ran234@gmail.com>
Thu, 26 Jul 2012 21:01:41 +0000 (00:01 +0300)
commit112cccb18ad1bc877b3c4a87fa536ea085c761b5
tree75a76da2d1b06752956a105de54c979d4a0e36b6
parentc6279b8baeae7dd9ff486bc0fb60ff0bef0587af
Some atom related optimizations

We often get a strdup'd string, just to pass it over the atom_intern and
then immediately free it. But atom_intern then strdup's it again (if
it's not interned already); so instead we can have the interning "steal"
the memory instead of allocing a new one and freeing the old one. This
is done by a new xkb_atom_steal function.

It also turns out, that every time we strdup an atom, we don't actually
modify it afterwards. Since we are guaranteed that the atom table will
live as long as the context, we can just use xkb_atom_text instead. This
removes a some more dynamic allocations.

For this change we had to remove the ability to append two strings, e.g.
    "foo" + "bar" -> "foobar"
which is only possible with string literals. This is unused and quite
useless for our purposes.

xkb_atom_strdup is left unused, as it may still be useful.

Running rulescomp in valgrind, Before:
==7907== total heap usage: 173,698 allocs, 173,698 frees, 9,775,973 bytes allocated
After:
==6348== total heap usage: 168,403 allocs, 168,403 frees, 9,732,648 bytes allocated

Signed-off-by: Ran Benita <ran234@gmail.com>
15 files changed:
src/alloc.c
src/atom.c
src/atom.h
src/context.c
src/xkb-priv.h
src/xkbcomp/action.c
src/xkbcomp/action.h
src/xkbcomp/compat.c
src/xkbcomp/expr.c
src/xkbcomp/expr.h
src/xkbcomp/keycodes.c
src/xkbcomp/keytypes.c
src/xkbcomp/parser.y
src/xkbcomp/symbols.c
src/xkbcomp/vmod.c