Convert permissions to lowercase inside the cache

Slight optimization, toLowerCase is a relatively expensive call in the scheme of permission checks.
This commit is contained in:
Luck 2018-11-24 13:09:26 +00:00
parent c19ef84116
commit 1544487e92
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 6 additions and 4 deletions

View File

@ -47,6 +47,8 @@ import java.util.Optional;
* <li>{@code org.bukkit.entity.Player}</li>
* <li>{@code net.md_5.bungee.api.connection.ProxiedPlayer}</li>
* <li>{@code org.spongepowered.api.service.permission.Subject}</li>
* <li>{@code cn.nukkit.Player}</li>
* <li>{@code com.velocitypowered.api.proxy.Player}</li>
* </ul>
*
* @since 4.0

View File

@ -81,10 +81,6 @@ public class PermissionCalculator implements Function<String, Tristate> {
* @return the result
*/
public Tristate getPermissionValue(String permission, PermissionCheckEvent.Origin origin) {
// convert the permission to lowercase, as all values in the backing map are also lowercase.
// this allows fast case insensitive lookups
permission = permission.toLowerCase();
// get the result
Tristate result = this.lookupCache.get(permission);
@ -97,6 +93,10 @@ public class PermissionCalculator implements Function<String, Tristate> {
@Override
public Tristate apply(@NonNull String permission) {
// convert the permission to lowercase, as all values in the backing map are also lowercase.
// this allows fast case insensitive lookups
permission = permission.toLowerCase();
// offer the permission to the permission vault
// we only need to do this once per permission, so it doesn't matter
// that this call is behind the cache.