It should be faster to call ```getLength(k+1)-getLength(k)``` from polyline because lengths are stored there and the compiler would only do a simple subtraction instead of actually calculating the distance.