gpt4 book ai didi

proguard - ProGuard 中假设nosideeffects 的使用

转载 作者:行者123 更新时间:2023-12-02 22:03:30 27 4
gpt4 key购买 nike

我读自 http://proguard.sourceforge.net/manual/usage.html关于assumenosideeffects的使用。我的问题涉及以下段落:

-assumenosideeffects class_specification Specifies methods that don't have any side effects (other than maybe returning a value). In the optimization step, ProGuard will then remove calls to such methods, if it can determine that the return values aren't used. ProGuard will analyze your program code to find such methods automatically. It will not analyze library code, for which this option can therefore be useful. For example, you could specify the method System.currentTimeMillis(), so that any idle calls to it will be removed. With some care, you can also use the option to remove logging code. Note that ProGuard applies the option to the entire hierarchy of the specified methods. Only applicable when optimizing. In general, making assumptions can be dangerous; you can easily break the processed code. Only use this option if you know what you're doing!

我需要了解 ProGuard 如何确定“未使用返回值”。特别是,如果方法调用不返回任何值,它们是否总是被删除?

最佳答案

if the method calls do not return any value, are they always removed?

答案是肯定的。 Chromium sources 就是一个例子。 :

private ChromeBrowserInitializer(Context context) {
mApplication = (ChromeApplication) context.getApplicationContext();
mHandler = new Handler(Looper.getMainLooper());
initLeakCanary();
}

@RemovableInRelease
private void initLeakCanary() {
// Watch that Activity objects are not retained after their onDestroy() has been called.
// This is a no-op in release builds.
LeakCanary.install(mApplication);
}

@RemovableInRelease注释的方法将从发布版本中删除。 chromium_code.flags :

# Remove methods annotated with this if their return value is unused.
-assumenosideeffects class ** {
@org.chromium.base.annotations.RemovableInRelease <methods>;
}

关于proguard - ProGuard 中假设nosideeffects 的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33109068/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com