From 6229d990828aae67089c642fb47ac5b6daaacd48 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Fri, 9 Jun 2017 13:35:48 +0100 Subject: [PATCH] LocalLog: Use LocalDateTime.now() instead of a Calendar. Calendars are cloned once per format argument they're used for and cloning a calendar is quite expensive. The line modified by this change used to create dozens of objects, most of them pointlessly cloned. Instead, we LocalDateTime, which is immutable and will be used directly. Moreover, we can rely on its toString method which is specified to format dates the same way we were doing in this class. Test: manual Change-Id: Ia2f6f5eb4f79252663c22b5a81d747c928771ee9 --- core/java/android/util/LocalLog.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/java/android/util/LocalLog.java b/core/java/android/util/LocalLog.java index 665c583a56aba..eb84479fef69d 100644 --- a/core/java/android/util/LocalLog.java +++ b/core/java/android/util/LocalLog.java @@ -18,10 +18,10 @@ package android.util; import java.io.FileDescriptor; import java.io.PrintWriter; -import java.util.Calendar; -import java.util.Iterator; -import java.util.Deque; +import java.time.LocalDateTime; import java.util.ArrayDeque; +import java.util.Deque; +import java.util.Iterator; /** * @hide @@ -40,9 +40,7 @@ public final class LocalLog { if (mMaxLines <= 0) { return; } - Calendar c = Calendar.getInstance(); - c.setTimeInMillis(System.currentTimeMillis()); - append(String.format("%tm-%td %tH:%tM:%tS.%tL - %s", c, c, c, c, c, c, msg)); + append(String.format("%s - %s", LocalDateTime.now(), msg)); } private synchronized void append(String logLine) {