question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unnecessary casts in InputMultiplexer source

See original GitHub issue

The InputMultiplexer stores InputProcessors with a SnapshotArray<InputProcessor>.

In all of the input events (KeyDown, KeyUp, …) the SnapshotArray is used to return the contained InputProcessors. 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 InputProcessors. 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:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Darkyenuscommented, Aug 20, 2019

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 type Object[] and not InputProcessor[], even if generics say otherwise (thanks to erasure). So the full change would also have to supply the InputProcessor.class to the SnapshotArray constructor.

0reactions
DeRealMorgancommented, Aug 20, 2019

Yes it it. I did not see that. So then this issue is pointless.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found