Optimized hazard curve export

Addresses https://bugs.launchpad.net/openquake/+bug/1099763.

See bug description and comments for detailed information about the profiling and optimizations I've done here.