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

Closes #1319.