Skip to content
Commit b7edebc8 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Fix inefficient CursorAnchorInfo#hashCode().

It turns out that the current CursorAnchorInfo#equals() is quite
inefficient because our CursorAnchorInfo#hashCode() tries to use almost
all the fields.  Even worse, as Matrix#hashCode() is hard-coded to 44,
we get the same hashCode() when comparing two CursorAnchorInfo objects
that are different only in transformation Matrix after such a complex
hash calculation.

In the real world scenarios, most likely calculation hash code only from
Matrix and composing text would be good enough for our use case, because
the former can cover UI scrolling scenario and the latter can cover the
text typing scenario.  More complex hash calculation is probably
inefficient.

With this CL, CursorAnchorInfo#hashCode() is pre-calculated only from
those two fields, and carefully reorder comparisons in
CursorAnchorInfo#equals() to improve the likelihood of returning false
with fewer comparisons.

Bug: 28105733
Change-Id: Id896adeab5ffe87ceddb2c2762d6d91475e28ec4
parent cf45224a
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment