Fix exponential perf degradation in Time.parse and Time.strptime.

Closes #1319.
Merge pull request #1572 from int3/master

Fix exponential perf degradation in Time.parse and Time.strptime.