Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5395b2af authored by Felipe Leme's avatar Felipe Leme
Browse files

Lazy load the allocation of Slog message formatting objects.

Test: manual verification looking at logcat output
Fixes: 182963900

Change-Id: If62ccfe085b20cda8755fefc3ec757ad59986685
parent d3d61ffe
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -30,11 +30,11 @@ import java.util.Locale;
 */
public final class Slog {

    @GuardedBy("sMessageBuilder")
    private static final StringBuilder sMessageBuilder = new StringBuilder();
    @GuardedBy("Slog.class")
    private static StringBuilder sMessageBuilder;

    @GuardedBy("sMessageBuilder")
    private static final Formatter sFormatter = new Formatter(sMessageBuilder, Locale.ENGLISH);
    @GuardedBy("Slog.class")
    private static Formatter sFormatter;

    private Slog() {
    }
@@ -226,7 +226,12 @@ public final class Slog {
    }

    private static String getMessage(String format, @Nullable Object... args) {
        synchronized (sMessageBuilder) {
        synchronized (Slog.class) {
            if (sMessageBuilder == null) {
                // Lazy load so they're not created if not used by the process
                sMessageBuilder = new StringBuilder();
                sFormatter = new Formatter(sMessageBuilder, Locale.ENGLISH);
            }
            sFormatter.format(format, args);
            String message = sMessageBuilder.toString();
            sMessageBuilder.setLength(0);