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

Commit 72c50814 authored by Peter Kalauskas's avatar Peter Kalauskas Committed by Android (Google) Code Review
Browse files

Merge "Reduce odex size by calling block inside traceSection only once" into main

parents 84696ecc 860650f3
Loading
Loading
Loading
Loading
+16 −18
Original line number Diff line number Diff line
@@ -39,32 +39,30 @@ import kotlinx.coroutines.withContext
 * Run a block within a [Trace] section. Calls [Trace.beginSection] before and [Trace.endSection]
 * after the passed block.
 */
inline fun <T> traceSection(tag: String, block: () -> T): T =
    if (Trace.isTagEnabled(Trace.TRACE_TAG_APP)) {
        Trace.traceBegin(Trace.TRACE_TAG_APP, tag)
        try {
inline fun <T> traceSection(tag: String, block: () -> T): T {
    val tracingEnabled = Trace.isTagEnabled(Trace.TRACE_TAG_APP)
    if (tracingEnabled) Trace.traceBegin(Trace.TRACE_TAG_APP, tag)
    return try {
        // Note that as this is inline, the block section would be duplicated if it is called
        // several times. For this reason, we're using the try/finally even if tracing is disabled.
        block()
    } finally {
            Trace.traceEnd(Trace.TRACE_TAG_APP)
        if (tracingEnabled) Trace.traceEnd(Trace.TRACE_TAG_APP)
    }
    } else {
        block()
}

/**
 * Same as [traceSection], but the tag is provided as a lambda to help avoiding creating expensive
 * strings when not needed.
 */
inline fun <T> traceSection(tag: () -> String, block: () -> T): T =
    if (Trace.isTagEnabled(Trace.TRACE_TAG_APP)) {
        Trace.traceBegin(Trace.TRACE_TAG_APP, tag())
        try {
inline fun <T> traceSection(tag: () -> String, block: () -> T): T {
    val tracingEnabled = Trace.isTagEnabled(Trace.TRACE_TAG_APP)
    if (tracingEnabled) Trace.traceBegin(Trace.TRACE_TAG_APP, tag())
    return try {
        block()
    } finally {
            Trace.traceEnd(Trace.TRACE_TAG_APP)
        if (tracingEnabled) Trace.traceEnd(Trace.TRACE_TAG_APP)
    }
    } else {
        block()
}

class TraceUtils {