convert template lookup from array to hash table

Speeds up compilation of template heavy code by maybe 10%.