Check if stylesheet exists before calling `put`

We only want to put an entry into the stylesheet cache if we have an
actual stylesheet.  This adds an if-clause that checks whether the
stylesheet pointer is not `NULL` before calling `put`.
Calculate the hash value outside of the mutex

There's no need to have the call to the hash function inside the mutex.

Also, micro-optimization for the win!