Open LeFisheAuCoordLogger opened 2 months ago
based and redpilled
100% Correct. I've deprecated this project in favor of a proper switch-case included in a project I'm working on. I did the implementation all wrong and somehow managed to make switch-case OOP.
What you have here is an autistic way of slowing down the program via an object oriented approach to a "switch case", which is really just a brute force/linear search as you keep adding cases until you find the matching value. This means that if we have a value that matches with the last "case", it will take longer for the program to reach it.
Switch cases are meant to be fast, they take an integer value, index a constant jump table (only initialized once in the program) and then jump to the corresponding instruction address. This indexing is done in a constant time complexity meaning every case takes the same time to be matched. In addition, if the switch case isn't broken, it falls through to the next case.
In a higher level (Java) this would be:
The most similar approach in Lua (efficiency wise) is initializing a constant table with functions as values and handle fall-throughs recursively:
I hope this clears up everything, consider renaming your "Switch Case" to "Redundant Object Oriented If Else".