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.

Note: https://github.com/gem/oq-engine/pull/1007 should land first for a clean diff.