GridPasswordView icon indicating copy to clipboard operation
GridPasswordView copied to clipboard

remove Enum to optimize the performance

Open songzhw opened this issue 9 years ago • 2 comments

官方文档( https://developer.android.com/training/articles/memory.html#Overhead )中提及尽量少用Enum。 GridPasswordView中的PasswordType可用简单的常量来代替。 若为了校验所提供的类型是否在范围之内,再加上@IntDef即好。

songzhw avatar May 23 '16 17:05 songzhw

PasswordType 只是用来 switch case,每个枚举中只有名字,没有其他字段,确实使用 @IntDef 更好。

BTY,在楼主提到的链接里,关于这段文档:

Enums often require more than twice as much memory as static constants. You should strictly avoid using enums on Android.

前几天我看到了一些相关的讨论:Java 枚举会比静态常量更消耗内存吗? - RednaxelaFX 的回答 - 知乎 这个“strictly avoid”有些争议。如果一个枚举项中需要加方法加字段,比如 FooEnum(String, Object),还是该用就用,自己写代码给 int 加字段不如直接用 enum。虽然 enum 性能不如 static final int,但是自己加方法加字段可能还不如 enum 处理的好。而 static final int 够用的情形下,还是 int 优先。

KANGOD avatar Aug 17 '16 09:08 KANGOD

0.3里面的车牌键盘,点击"V"字母的时候变成了"L"这是个小bug吗,麻烦作者最好改下

LoveYourselfAndMe avatar Jul 28 '17 01:07 LoveYourselfAndMe