Improve the performance of undo ops grouping on large states

Continuous typing causes the undo states to potentially become extremely large. The naive assumption that some of the arrays in use would stay small causes immense slow-downs when determining whether to create a new undo state.

These bottlenecks have now been removed, and the search depth of various grouping conditions have been limited to psmaller sizes.