Cache the creation of Sponge proxy subject classes (#1005)

This commit is contained in:
Luck 2018-05-17 18:19:45 +01:00
parent ed3b5a3cf1
commit f4882c1c14
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 13 additions and 3 deletions

View File

@ -61,6 +61,8 @@ public abstract class HolderSubject<T extends PermissionHolder> implements LPSub
private final HolderSubjectData subjectData;
private final HolderSubjectData transientSubjectData;
private Subject spongeSubject = null;
HolderSubject(LPSpongePlugin plugin, T parent) {
this.parent = parent;
this.plugin = plugin;
@ -78,8 +80,11 @@ public abstract class HolderSubject<T extends PermissionHolder> implements LPSub
}
@Override
public Subject sponge() {
return ProxyFactory.toSponge(this);
public synchronized Subject sponge() {
if (this.spongeSubject == null) {
this.spongeSubject = ProxyFactory.toSponge(this);
}
return this.spongeSubject;
}
@Override

View File

@ -62,6 +62,8 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject {
private final PersistedSubjectData subjectData;
private final CalculatedSubjectData transientSubjectData;
private Subject spongeSubject = null;
/**
* The save buffer instance for saving changes to disk
*/
@ -124,7 +126,10 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject {
@Override
public Subject sponge() {
return ProxyFactory.toSponge(this);
if (this.spongeSubject == null) {
this.spongeSubject = ProxyFactory.toSponge(this);
}
return this.spongeSubject;
}
@Override