fossasia / pslab-android

PSLab Android App https://play.google.com/store/apps/details?id=io.pslab
https://pslab.io
Apache License 2.0
2.05k stars 804 forks source link

Suggestion: Improvement of Java Autoboxing and Unboxing #1528

Closed o0lwj0o closed 5 years ago

o0lwj0o commented 5 years ago

Hi, I have found some usage of “int a = Integer.valueOf(String)” in this project. In fact the return type of “Integer.valueOf()” is “Integer” which is wrapper class. Wrapper class stores in the heap rather than stack. It take more time to loopup. The other potential problem is that Java implement autoboxing and unboxing since JDK 1.5. If run this in low version JDK, it may get trouble. Furthermore, in the above case, it need to cast Integer to int. I recommend use “Integer.parseInt(String)” which return type is int to improve its performance.

PS: This case also applies to “double-Doubel”, “float-Float”, “long-Long” and so on.

Detail websites and lines are listed below

Double.valueOf() | 73 91 | https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/others/EditTextWidget.java | 41 | https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/others/FloatSeekBar.java

Float.valueOf() | 308 | https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/fragment/ControlFragmentAdvanced.java

Integer.valueOf() | 616 641 743 768 869 894 | https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/adapters/ControlMainAdapter.java

Best regards

harsh-2711 commented 5 years ago

@o0lwj0o Great catch. I will surely remove the autoboxing issue from all the classes. I also figured out that some of our lists also faces same issue. I will change them all at once.

Yahhi commented 5 years ago

I already did it in https://github.com/fossasia/pslab-android/pull/1525

angmas1 commented 5 years ago

Is anyone working on this? If not can I work on this?

neel1998 commented 5 years ago

@harsh-2711 what's the status of this issue. If it not solved yet, i would like to take it up otherwise you can close this issue