Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Faster world lookup #4420

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
*/
package com.plotsquared.bukkit.util;

import com.google.common.collect.Maps;
import com.plotsquared.core.location.World;
import org.bukkit.Bukkit;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.IdentityHashMap;
import java.util.Map;

public class BukkitWorld implements World<org.bukkit.World> {

private static final Map<String, BukkitWorld> worldMap = Maps.newHashMap();
private static final Map<org.bukkit.World, BukkitWorld> worldMap = new IdentityHashMap<>();
private static final boolean HAS_MIN_Y;

static {
Expand Down Expand Up @@ -68,13 +68,7 @@ private BukkitWorld(final org.bukkit.World world) {
* @return World instance
*/
public static @NonNull BukkitWorld of(final org.bukkit.World world) {
BukkitWorld bukkitWorld = worldMap.get(world.getName());
if (bukkitWorld != null && bukkitWorld.getPlatformWorld().equals(world)) {
return bukkitWorld;
}
bukkitWorld = new BukkitWorld(world);
worldMap.put(world.getName(), bukkitWorld);
return bukkitWorld;
return worldMap.computeIfAbsent(world, BukkitWorld::new);
}

/**
Expand Down
Loading