Lots of optimizations here and there in the library.

Review of all the javalib and the library with optimizations
in mind (and knowing what the optimizer can do).