Speed up template rendering for large pages, thanks to Moritz Lenz (noris network AG).

Squashed commit of the following:

commit a1992a97faf2b35f225187b97d062c6127461c54
Author: Moritz Lenz <mlenz@noris.net>
Date:   Mon Sep 9 10:56:25 2013 +0200

    Speed up Kernel::Output:HTML::Layout->Output

    While profiling several requests, I noticed that when the caches
    are warm, more than half of the time was spent in the template
    engine, and about 3/4 of that time in _BlockTemplateReplace.

    This patch speeds up _BlockTemplateReplace from 8.85s to 4.68s in this
    particular case, speeding up the total request time by 21%.

    It achieves this by not doing the global substitution for each block name,
    but instead doing it per block nesting level. Thus fewer regexes need to be
    compiled, and fewer passes over the whole string need to be performed.