From c95d9381680c579a9f46aa7c7d7353d168eb8082 Mon Sep 17 00:00:00 2001 From: Robert Greenwalt Date: Fri, 11 Oct 2013 12:38:07 -0700 Subject: 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 --- wifi/java/android/net/wifi/WifiStateMachine.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'wifi') 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(); 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())); -- cgit v1.1