Using empty() instead of size() == 0
Minor performance improvements

Assign arity of 0 directly to leaves, rather than using get_arity().

Re-ordered switch statement by probability.