Refactor code splitter a bit.
Refactor code splitter a bit.

Move constant out of the loop and rearrange common bits together.

Titan-C/sphinx-gallery,lesteve/sphinx-gallery,Eric89GXL/sphinx-gallery,sphinx-gallery/sphinx-gallery,sphinx-gallery/sphinx-gallery,Titan-C/sphinx-gallery,Eric89GXL/sphinx-gallery,lesteve/sphinx-gallery