Example:
// Before
public void AddPosition(IntVector2 newValue) {
var component = CreateComponent<PositionComponent>(CoreComponentsLookup.Position);
component.value = newValue;
AddComponent(CoreComponentsLookup.Position, component);
}
// After
public void AddPosition(IntVector2 newValue) {
var index = CoreComponentsLookup.Position;
var component = CreateComponent<PositionComponent>(index);
component.value = newValue;
AddComponent(index, component);
}
Welcome to the world of micro-optimizations
Is that not the same thing? How is that faster?
The difference is that the new variable index is used twice. The compiler won't reuse the same variable for that as it doesn't know what CoreComponentsLookup.Position does. It could have side effects for example.
Ooh. Yes I know that. I overlooked the second use of the lookup variable lol. faster by 1 statement. 馃憤
It'd be cool to see a benchmark and how those changes impact the performance :D
Feel free to do one :)
I don't expect any real life gains unless you call those methods reeeeeaaaly often. I'd call it code maintenance...
Most helpful comment
The difference is that the new variable
indexis used twice. The compiler won't reuse the same variable for that as it doesn't know whatCoreComponentsLookup.Positiondoes. It could have side effects for example.