Skip to content

Commit

Permalink
Replace HashMap with SparseArray in UsbMidiDeviceAndroid.java.
Browse files Browse the repository at this point in the history
Android lint suggests replacing HashMap<Integer, Xyz> with
SparseArray<Xyz> for better memory efficiency.

BUG=347356
NOTRY=true

Review URL: https://codereview.chromium.org/181593009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254583 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
newt@chromium.org committed Mar 3, 2014
1 parent 8acc1d9 commit 37d973f
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.hardware.usb.UsbInterface;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbRequest;
import android.util.SparseArray;

import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
Expand All @@ -33,7 +34,7 @@ class UsbMidiDeviceAndroid {
/**
* A map from endpoint number to UsbEndpoint.
*/
private final Map<Integer, UsbEndpoint> mEndpointMap;
private final SparseArray<UsbEndpoint> mEndpointMap;

/**
* A map from UsbEndpoint to UsbRequest associated to it.
Expand All @@ -52,7 +53,7 @@ class UsbMidiDeviceAndroid {
*/
UsbMidiDeviceAndroid(UsbManager manager, UsbDevice device) {
mConnection = manager.openDevice(device);
mEndpointMap = new HashMap<Integer, UsbEndpoint>();
mEndpointMap = new SparseArray<UsbEndpoint>();
mRequestMap = new HashMap<UsbEndpoint, UsbRequest>();

for (int i = 0; i < device.getInterfaceCount(); ++i) {
Expand Down Expand Up @@ -81,14 +82,12 @@ void send(int endpointNumber, byte[] bs) {
if (mConnection == null) {
return;
}
if (!mEndpointMap.containsKey(endpointNumber)) {
UsbEndpoint endpoint = mEndpointMap.get(endpointNumber);
if (endpoint == null) {
return;
}
UsbEndpoint endpoint = mEndpointMap.get(endpointNumber);
UsbRequest request;
if (mRequestMap.containsKey(endpoint)) {
request = mRequestMap.get(endpoint);
} else {
UsbRequest request = mRequestMap.get(endpoint);
if (request == null) {
request = new UsbRequest();
request.initialize(mConnection, endpoint);
mRequestMap.put(endpoint, request);
Expand Down

0 comments on commit 37d973f

Please sign in to comment.