mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-02-06 23:52:03 +01:00
NodeMap optimizations
This commit is contained in:
parent
da253c47da
commit
233324f6c9
@ -134,19 +134,28 @@ public final class NodeMap {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean flagExcludeTest(Flag flag, String contextKey, QueryOptions filter, ImmutableContextSet contextSet) {
|
||||||
|
// return true (negative result) if the explicit *include* flag is not set, and if the context set doesn't contain the required context key.
|
||||||
|
return !filter.flag(flag) && !contextSet.containsKey(contextKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean normalNodesExcludeTest(QueryOptions filter, ImmutableContextSet contextSet) {
|
||||||
|
// return true (negative result) if normal nodes should not be included due to the lack of a server/world context.
|
||||||
|
return flagExcludeTest(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT, DefaultContextKeys.SERVER_KEY, filter, contextSet) ||
|
||||||
|
flagExcludeTest(Flag.INCLUDE_NODES_WITHOUT_WORLD_CONTEXT, DefaultContextKeys.WORLD_KEY, filter, contextSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean inheritanceNodesIncludeTest(QueryOptions filter, ImmutableContextSet contextSet) {
|
||||||
|
// return true (positive result) if inheritance nodes should be included, due to the lack of any flags preventing their inclusion.
|
||||||
|
return !flagExcludeTest(Flag.APPLY_INHERITANCE_NODES_WITHOUT_SERVER_CONTEXT, DefaultContextKeys.SERVER_KEY, filter, contextSet) &&
|
||||||
|
!flagExcludeTest(Flag.APPLY_INHERITANCE_NODES_WITHOUT_WORLD_CONTEXT, DefaultContextKeys.WORLD_KEY, filter, contextSet);
|
||||||
|
}
|
||||||
|
|
||||||
public void copyTo(Collection<? super Node> collection, QueryOptions filter) {
|
public void copyTo(Collection<? super Node> collection, QueryOptions filter) {
|
||||||
for (Map.Entry<ImmutableContextSet, SortedSet<Node>> e : this.map.entrySet()) {
|
for (Map.Entry<ImmutableContextSet, SortedSet<Node>> e : this.map.entrySet()) {
|
||||||
if (filter.satisfies(e.getKey())) {
|
if (filter.satisfies(e.getKey())) {
|
||||||
boolean serverMissing = !e.getKey().containsKey(DefaultContextKeys.SERVER_KEY);
|
if (normalNodesExcludeTest(filter, e.getKey())) {
|
||||||
boolean worldMissing = !e.getKey().containsKey(DefaultContextKeys.WORLD_KEY);
|
if (inheritanceNodesIncludeTest(filter, e.getKey())) {
|
||||||
boolean excludeAsServerMissing = !filter.flag(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT) && serverMissing;
|
|
||||||
boolean excludeAsWorldMissing = !filter.flag(Flag.INCLUDE_NODES_WITHOUT_WORLD_CONTEXT) && worldMissing;
|
|
||||||
|
|
||||||
if (excludeAsServerMissing || excludeAsWorldMissing) {
|
|
||||||
boolean excludeInheritanceAsServerMissing = !filter.flag(Flag.APPLY_INHERITANCE_NODES_WITHOUT_SERVER_CONTEXT) && serverMissing;
|
|
||||||
boolean excludeInheritanceAsWorldMissing = !filter.flag(Flag.APPLY_INHERITANCE_NODES_WITHOUT_WORLD_CONTEXT) && worldMissing;
|
|
||||||
|
|
||||||
if (!excludeInheritanceAsServerMissing && !excludeInheritanceAsWorldMissing) {
|
|
||||||
// only copy inheritance nodes.
|
// only copy inheritance nodes.
|
||||||
SortedSet<InheritanceNode> inheritanceNodes = this.inheritanceMap.get(e.getKey());
|
SortedSet<InheritanceNode> inheritanceNodes = this.inheritanceMap.get(e.getKey());
|
||||||
if (inheritanceNodes != null) {
|
if (inheritanceNodes != null) {
|
||||||
@ -163,12 +172,7 @@ public final class NodeMap {
|
|||||||
public void copyInheritanceNodesTo(Collection<? super InheritanceNode> collection, QueryOptions filter) {
|
public void copyInheritanceNodesTo(Collection<? super InheritanceNode> collection, QueryOptions filter) {
|
||||||
for (Map.Entry<ImmutableContextSet, SortedSet<InheritanceNode>> e : this.inheritanceMap.entrySet()) {
|
for (Map.Entry<ImmutableContextSet, SortedSet<InheritanceNode>> e : this.inheritanceMap.entrySet()) {
|
||||||
if (filter.satisfies(e.getKey())) {
|
if (filter.satisfies(e.getKey())) {
|
||||||
boolean serverMissing = !e.getKey().containsKey(DefaultContextKeys.SERVER_KEY);
|
if (inheritanceNodesIncludeTest(filter, e.getKey())) {
|
||||||
boolean worldMissing = !e.getKey().containsKey(DefaultContextKeys.WORLD_KEY);
|
|
||||||
boolean excludeInheritanceAsServerMissing = !filter.flag(Flag.APPLY_INHERITANCE_NODES_WITHOUT_SERVER_CONTEXT) && serverMissing;
|
|
||||||
boolean excludeInheritanceAsWorldMissing = !filter.flag(Flag.APPLY_INHERITANCE_NODES_WITHOUT_WORLD_CONTEXT) && worldMissing;
|
|
||||||
|
|
||||||
if (!excludeInheritanceAsServerMissing && !excludeInheritanceAsWorldMissing) {
|
|
||||||
collection.addAll(e.getValue());
|
collection.addAll(e.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,7 +197,7 @@ public final class NodeMap {
|
|||||||
*/
|
*/
|
||||||
void invalidate() {
|
void invalidate() {
|
||||||
this.mapCache.invalidate();
|
this.mapCache.invalidate();
|
||||||
this.inheritanceMapCache.get();
|
this.inheritanceMapCache.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node localise(Node node) {
|
private Node localise(Node node) {
|
||||||
|
Loading…
Reference in New Issue
Block a user