Fix potentially exceeding call stack limit

For very large WKT strings, the iterations inside the parser _may_ cause the call stack run into its limit.
This PR fixes this by a simple rewrite, that also improves the speed significantly! 

Fixes #2590.