Remove duplicate positions from polylines.

For #898.
Let's optimize this by saving the index of the first duplicate and using that to start the loop below.