Due to dead code elimination I usually do: ``` if...
# android
f
Due to dead code elimination I usually do:
Copy code
if (BuildConfig.DEBUG) Timber.d(...)
Is the compiler smart enough to do the same if I make an inline function for that check?
d
Why don’t you plant Timber tree only if BuildConfig.DEBUG?
f
I have a debug tree, I'm not sure what you're getting at? The point is to remove unused code. Without that if check (and dead code elimination) any log call would be called, but it wouldn't print it.
d
maybe you have ProGuard rules like that:
Copy code
-assumenosideeffects class timber.log.Timber* {
    public static *** v(...);
    public static *** d(...);
    public static *** i(...);
}
f
ProGuard cannot remove the variables that are used indirectly though. So this use case cannot be solved by the rule above:
Copy code
if (BuildConfig.DEBUG) {
    val foo = expensiveBar()
    Timber.d("Critical: ${foo.bar}")
}
So what I'm looking for is some way to do dead code elimination without wrapping it in the explicit
BuildConfig.DEBUG
check 🙂
And the question is if the compiler is smart enough to infer that from an inline function. I'll test it. I was just wondering if someone knew.
d
I am not sure that the compiler performs dead code elimination on the first example even. The JVM will take care of it nonetheless.