diff options
author | Robert Greenwalt <rgreenwalt@google.com> | 2013-10-11 12:38:07 -0700 |
---|---|---|
committer | Robert Greenwalt <rgreenwalt@google.com> | 2013-10-11 14:18:26 -0700 |
commit | c95d9381680c579a9f46aa7c7d7353d168eb8082 (patch) | |
tree | 4768371a2c215e3c7bbec51d8169e7ef4f8a3386 /wifi | |
parent | 140ae7bdadd13d3b849385636e1811438e62ed6a (diff) | |
download | frameworks_base-c95d9381680c579a9f46aa7c7d7353d168eb8082.zip frameworks_base-c95d9381680c579a9f46aa7c7d7353d168eb8082.tar.gz frameworks_base-c95d9381680c579a9f46aa7c7d7353d168eb8082.tar.bz2 |
Make Wifi Scans more heap-efficient
We were ending up with 1 reference to every char array
in which a new AP was discovered. In a busy env this could
cost several hundred K from the dalvik heap.
bug:11087956
Change-Id: I3b14c39fd0c98e4aea08a406e80bcf6af40d0664
Diffstat (limited to 'wifi')
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index b4c583e..4bc3dda 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -1031,7 +1031,8 @@ public class WifiStateMachine extends StateMachine { int dist, distSd; long tsf = 0; dist = distSd = ScanResult.UNSPECIFIED; - long now = SystemClock.elapsedRealtime(); + final long now = SystemClock.elapsedRealtime(); + final int bssidStrLen = BSSID_STR.length(); while (true) { while (n < splitData.length) { @@ -1068,7 +1069,8 @@ public class WifiStateMachine extends StateMachine { } else if (splitData[n].equals(TRUNCATED)) { batchedScanResult.truncated = true; } else if (splitData[n].startsWith(BSSID_STR)) { - bssid = splitData[n].substring(BSSID_STR.length()); + bssid = new String(splitData[n].getBytes(), bssidStrLen, + splitData[n].length() - bssidStrLen); } else if (splitData[n].startsWith(FREQ_STR)) { try { freq = Integer.parseInt(splitData[n].substring(FREQ_STR.length())); @@ -1864,10 +1866,12 @@ public class WifiStateMachine extends StateMachine { synchronized(mScanResultCache) { mScanResults = new ArrayList<ScanResult>(); String[] lines = scanResults.split("\n"); + final int bssidStrLen = BSSID_STR.length(); + final int flagLen = FLAGS_STR.length(); for (String line : lines) { if (line.startsWith(BSSID_STR)) { - bssid = line.substring(BSSID_STR.length()); + bssid = new String(line.getBytes(), bssidStrLen, line.length() - bssidStrLen); } else if (line.startsWith(FREQ_STR)) { try { freq = Integer.parseInt(line.substring(FREQ_STR.length())); @@ -1891,7 +1895,7 @@ public class WifiStateMachine extends StateMachine { tsf = 0; } } else if (line.startsWith(FLAGS_STR)) { - flags = line.substring(FLAGS_STR.length()); + flags = new String(line.getBytes(), flagLen, line.length() - flagLen); } else if (line.startsWith(SSID_STR)) { wifiSsid = WifiSsid.createFromAsciiEncoded( line.substring(SSID_STR.length())); |