linkedin / Spyglass

A library for mentions on Android
Apache License 2.0
387 stars 128 forks source link

Optimize search start and search end index computation while finding … #134

Open amansaryal opened 1 year ago

amansaryal commented 1 year ago

While finding the current token, WordTokenizer would run through all MentionSpans in the text to determine the span index closest to the cursor on either side. This is rather wasteful and, in the case of getSearchEndIndex(), even unnecessary.

The idea is to use nextSpanTransition() to iterate sequentially till the cursor over batches of spans to get the closest last span end index in getSearchStartIndex.

For getSearchEndIndex, nextSpanTransition() does exactly what it needs without ever looking at any MentionSpans.