app freeze when applying links to large texts with a lot of links
Opened this issue · 0 comments
The problem occurs when we have a text with about 3000 symbols, all made of "www.gmail.com www.gmail.com www.gmail.com..." about 230 of them, there are 26 000 for loop iterations in SpannableStringInternal.getSpans() :
at android.text.SpannableStringInternal.getSpans(SpannableStringInternal.java:216)
at android.text.SpannableString.getSpans(SpannableString.java:25)
at android.text.SpannableStringInternal.sendSpanAdded(SpannableStringInternal.java:310)
at android.text.SpannableStringInternal.setSpan(SpannableStringInternal.java:138)
at android.text.SpannableString.setSpan(SpannableString.java:46)
at com.klinker.android.link_builder.LinkBuilder.applyLink(LinkBuilder.java:226)
at com.klinker.android.link_builder.LinkBuilder.addLinkToSpan(LinkBuilder.java:199)
at com.klinker.android.link_builder.LinkBuilder.addLinkToSpan(LinkBuilder.java:174)
at com.klinker.android.link_builder.LinkBuilder.build(LinkBuilder.java:148)
The problems seems that after every setSpan() call there is a sendSpanAdded() call, which triggers the getSpans(), which iterates for every span it has.