Closed Bug 1175321 Opened 6 years ago Closed 9 months ago

[Linter: UseSparseArrays] Consider using SparseArray for HashMap in Tabs.java

Categories

(Firefox for Android Graveyard :: General, defect)

All
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INCOMPLETE

People

(Reporter: mcomella, Unassigned)

References

Details

via lint:

../../src/main/java/org/mozilla/gecko/Tabs.java:53: Use new SparseArray<Tab>(...) instead for better performance

  50     private volatile Tab mSelectedTab;
  51 
  52     // All accesses to mTabs must be synchronized on the Tabs instance.
  53     private final HashMap<Integer, Tab> mTabs = new HashMap<Integer, Tab>();
  54 
  55     private AccountManager mAccountManager;

Priority: 4 / 10
Category: Performance
Severity: Warning
Explanation: HashMap can be replaced with SparseArray.
For maps where the keys are of type integer, it's typically more efficient to use the Android SparseArray API. This check identifies scenarios where you might want to consider using SparseArray instead of HashMap for better performance.

This is particularly useful when the value types are primitives like ints, where you can use SparseIntArray and avoid auto-boxing the values from int to Integer.

If you need to construct a HashMap because you need to call an API outside of your control which requires a Map, you can suppress this warning using for example the @SuppressLint annotation.

---

Unlike bug 963873, I can't make the assumption that we will have very few gamepads (and thus a small affect on performance) – as per Richard's suggestion in bug 962968 comment 12.
We have completed our launch of our new Firefox on Android. The development of the new versions use GitHub for issue tracking. If the bug report still reproduces in a current version of [Firefox on Android nightly](https://play.google.com/store/apps/details?id=org.mozilla.fenix) an issue can be reported at the [Fenix GitHub project](https://github.com/mozilla-mobile/fenix/). If you want to discuss your report please use [Mozilla's chat](https://wiki.mozilla.org/Matrix#Connect_to_Matrix) server https://chat.mozilla.org and join the [#fenix](https://chat.mozilla.org/#/room/#fenix:mozilla.org) channel.
Status: NEW → RESOLVED
Closed: 9 months ago
Resolution: --- → INCOMPLETE
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.