More optimization of dumpsys output.
There are three major classes of changes here:
- Avoid writing lines where their values are often empty, false, or some other typical thing.
- Use partial writes to the PrintWriter to avoid creating temporary strings.
- Use StringBuilder where we need to generate real String objects (and where possible cache the result).
diff --git a/services/java/com/android/server/am/BroadcastFilter.java b/services/java/com/android/server/am/BroadcastFilter.java
index cd7f720..0eeb393 100644
--- a/services/java/com/android/server/am/BroadcastFilter.java
+++ b/services/java/com/android/server/am/BroadcastFilter.java
@@ -18,6 +18,7 @@
import android.content.IntentFilter;
import android.util.PrintWriterPrinter;
+import android.util.Printer;
import java.io.PrintWriter;
@@ -33,19 +34,25 @@
requiredPermission = _requiredPermission;
}
- public void dumpLocal(PrintWriter pw, String prefix) {
- super.dump(new PrintWriterPrinter(pw), prefix);
- }
-
public void dump(PrintWriter pw, String prefix) {
- dumpLocal(pw, prefix);
- pw.println(prefix + "requiredPermission=" + requiredPermission);
+ dumpInReceiverList(pw, new PrintWriterPrinter(pw), prefix);
receiverList.dumpLocal(pw, prefix);
}
+ public void dumpInReceiverList(PrintWriter pw, Printer pr, String prefix) {
+ super.dump(pr, prefix);
+ if (requiredPermission != null) {
+ pw.print(prefix); pw.print("requiredPermission="); pw.println(requiredPermission);
+ }
+ }
+
public String toString() {
- return "BroadcastFilter{"
- + Integer.toHexString(System.identityHashCode(this))
- + " " + receiverList + "}";
+ StringBuilder sb = new StringBuilder();
+ sb.append("BroadcastFilter{");
+ sb.append(Integer.toHexString(System.identityHashCode(this)));
+ sb.append(' ');
+ sb.append(receiverList);
+ sb.append('}');
+ return sb.toString();
}
}