Saturn

Saturn

25M Downloads

pointless pointfree overwrite

quat1024 opened this issue ยท 0 comments

commented

/**
* @reason Avoid unnecessary object creation.
* @author AbdElAziz
* @since 0.0.8
* */
@Overwrite (remap = false)
@SuppressWarnings("ConstantConditions")
public Function<DynamicOps<?>, T> evalCached() {
if (!initialized) {
synchronized (this) {
if (!initialized) {
initialized = true;
}
}
}
return eval();
}

this does a volatile read of initialized and runs through a synchronized block for no reason, because this overwrite removes the only place initialized is actually used

also it doesn't avoid any object creation right? the object is already created at the call to eval(), storing the object in a field is not what causes it to be created

if you are going to do this patch, (which just by looking at it, i am not sure if it's a good optimization because it removes a cache that's probably there for a reason), why not something like this

@Overwrite
public Function<DynamicOps<?>, T> evalCached() { 
    return eval();
}