summaryrefslogtreecommitdiff
path: root/rs/java/android/renderscript/ProgramStore.java
diff options
context:
space:
mode:
authorSeigo Nonaka <nona@google.com>2020-10-14 15:04:01 -0700
committerSeigo Nonaka <nona@google.com>2020-10-15 18:24:35 -0700
commit31bf860bb645516c20e8920ca2e5e2fac6353bd8 (patch)
tree916e3ff2d13c4b7308c0e60a1d21050e0022e138 /rs/java/android/renderscript/ProgramStore.java
parentfad96cd68d9eb79ad02f00ac32fd0a2b50db7032 (diff)
Improve Font#equals and Font#hashCode for HashMap.
Font#equals and Font#hashCode reads bytes in the buffer and end up with bad performance if we use it as key of HashMap. To improve them, does following. - Font#hashCode Use buffer size as hash. Since we only accept OpenType compliant font files (invalid font data will be IllegalArgumentException in ctor), the hash collision due to same file size is unlikely happens. The ByteBuffer#hashCode includes head position as hashCode but intentionally exclude them from new hashCode since the head position is not used by platform include native code. - Font#equals The ByteBuffer is frequently duplicated for many reasons, e.g. having different reading head, etc, but the underlying mmaped memory address has not changed. Fortunately we have this address in underlying font object. Compare them as a shortcut of content equality. With this change, the local benchmark for the Font key-ed HashMap look up gets faster from 30ms to 4us. (on Pixel 3a) Bug: 170494256 Test: atest FontTest Change-Id: Ibc7f7aae0b3427e71209444eebb93753c340b711
Diffstat (limited to 'rs/java/android/renderscript/ProgramStore.java')
0 files changed, 0 insertions, 0 deletions