hi, i have a method but it's heavy in performance, i am trying to optimize it, so this is the method body but i want to optimize it more by adding if else statements that runs first to check if x, y, z has the same data, so if x, y, z has the same data this code shouldn't be run
//if x, y, z has the same value of it, let's say (x = 10, y = 10, z = 10) and the returned value of blockToSectionCoord is 10, this calculations should be stopped //so the method returns the TestClass(x, y, z) a lot more faster //disable assigning values if the returned data is the same int x = blockToSectionCoord(pos.getX()); int y = blockToSectionCoord(pos.getY()); int z = blockToSectionCoord(pos.getZ());
the reason of stopping this code is that
if x = 10, y = 10, z = 10
and the returned value of blockToSectionCoord(pos.getX)) and blockToSectionCoord(pos.getY()); and blockToSectionCoord(pos.getZ());` is the same = 10
duplicating this calculations is necessary
Also does adding if else statement to avoid duplicating the calculations will be faster than this?