This is a follow-up to r362293 which fixed exponential time needed
for mangling certain templates. This fixes the same issue if that
template pattern happens in template arguments > 10: The first
ten template arguments can use back references, and r362293 added
caching for back references. For latter arguments, we have to add
a cache for the mangling itself instead.
Fixes PR42091 even more.
Here's a thought: could we get by with one map? I think we can be certain that nothing mangles to integer literals between 0 and 9, since otherwise the demangler couldn't distinguish those from back references. So, can we keep the string map, and insert the string "0", "1", etc for back referenced things?