Use staticmutable variables to store information about last call to positionFromCursor.
As most of the time the cursor is close to the previous position, avoid to calculate every time the size of the lines from the beginning of the document, just calculate it from the previous cursor position.