Another round of performance improvements

This pull request contains quite drastic performance improvements. In my (simplistic) benchmarks for the IPSet class, performance doubled or tripled for operations like ipset.add(IPNetwork(...)), ip_address in ipset, ipset.remove(IPNetwork(...)).

It also contains a fix for a test case that always works for Python 2 (probably hits some implementation detail of C-Python). But after making some unrelated code changes it started failing under Python 3.3, because str(dictionary) returned the dictionary's items in a different order.