Unnecessary casts in InputMultiplexer source
See original GitHub issueThe InputMultiplexer
stores InputProcessor
s with a SnapshotArray<InputProcessor>
.
In all of the input events (KeyDown, KeyUp, …) the SnapshotArray
is used to return the contained InputProcessor
s. Then the event is delegated to each of the Processors.
Example:
public boolean keyDown (int keycode) {
Object[] items = processors.begin();
try {
for (int i = 0, n = processors.size; i < n; i++)
if (((InputProcessor)items[i]).keyDown(keycode)) return true;
} finally {
processors.end();
}
return false;
}
processors.begin()
returns the contained InputProcessor
s. They are generalized to an Object[]
array only to be cast to a InputProcessor
again in the for-loop.
This can and should be changed in all of the methods to this:
public boolean keyTyped (char character) {
InputProcessor[] items = processors.begin();
try {
for (int i = 0, n = processors.size; i < n; i++)
if (items[i].keyTyped(character)) return true;
} finally {
processors.end();
}
return false;
}
Also a small note: As the InputMultiplexer
is implementing the methods of the InputProcessor
interface, all of these methods should be marked as @Override
for readability.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Remove redundant casts in Java - Stack Overflow
There, edit a profile, go to the "Unnecessary Code" Tab and check "Remove unnecessary casts". Then right-click your source root and klick Source...
Read more >Getting Started with Chisel
The following tutorials will explain features of. Chisel by presenting source code examples. The repository is split into examples, ...
Read more >IDE0004: Remove unnecessary cast - .NET - Microsoft Learn
This rule flags unnecessary type casts. A cast expression is unnecessary if the code semantics would be identical with or without it.
Read more >4. Basic Digital Circuits
In particular, all Boolean expressions formed with AND and OR operations can be cast into a CMOS gate if all variables appear in...
Read more >Appendix A. Verilog Code of Design Examples - Springer Link
no conversion int -> logic vector necessary ... begin : INPUTMUX integer I; ... VHDL or qv.tcl for Verilog available in the source...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We are all volunteers here and the current state of the project is that people work mostly on things that matter to them. Since this is not a bug report nor any significant improvement, nobody will work on this and it will sit in the issue tracker forever, which is pointless for such a small change, so it is better to just close it. If you cared enough about this change, you would make a PR for it - people on discord/IRC will be happy to help you with it if you encounter any problems.
Btw. the suggested change would not work: since the
SnapshotArray
is initialized without a type, the returned array will indeed be of typeObject[]
and notInputProcessor[]
, even if generics say otherwise (thanks to erasure). So the full change would also have to supply theInputProcessor.class
to theSnapshotArray
constructor.Yes it it. I did not see that. So then this issue is pointless.