Micro optimizations to the template parameter parser
I somehow managed to loose a whole bunch of optimizations I did while
working on Id19503a. They can still be seen at
https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/FileImporter/+/441820/5..4/src/Services/WikiTextContentCleaner.php
This patch re-applies these optimizations again.
Bug: T194505
Change-Id: Ib77e8d580e7792796131770b67bd0ac4b57cddcf