From 18cd8f67cb118bc72ae5216ad1209ac9115c5ef8 Mon Sep 17 00:00:00 2001 From: Sotr Date: Wed, 10 Apr 2019 03:46:22 +0800 Subject: [PATCH] Revert "Improve performance for isOp and more" This reverts commit 17e0e3edca0efc58aaa5e85fb993029bc8780f7c. --- .../java/net/minecraft/server/JsonList.java | 36 ++++--------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/src/main/java/net/minecraft/server/JsonList.java b/src/main/java/net/minecraft/server/JsonList.java index 9bae7a21e..2c69fffd9 100644 --- a/src/main/java/net/minecraft/server/JsonList.java +++ b/src/main/java/net/minecraft/server/JsonList.java @@ -12,11 +12,8 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import com.koloboke.collect.map.hash.HashObjObjMaps; import com.mojang.authlib.GameProfile; -import io.akarin.server.core.AkarinAsyncExecutor; - import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -27,13 +24,10 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.logging.Level; - import javax.annotation.Nullable; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -47,7 +41,7 @@ public class JsonList> { protected final Gson b; private final File c; // Paper - replace HashMap is ConcurrentHashMap - protected Map d = Collections.emptyMap(); private final Map getBackingMap() { return this.d; } // Paper - OBFHELPER // Akarin + protected final Map d = Maps.newConcurrentMap(); private final Map getBackingMap() { return this.d; } // Paper - OBFHELPER private boolean e = true; private static final ParameterizedType f = new ParameterizedType() { public Type[] getActualTypeArguments() { @@ -85,11 +79,7 @@ public class JsonList> { } public void add(V v0) { - // Akarin start - Map toImmutable = HashObjObjMaps.newUpdatableMap(this.getBackingMap()); - toImmutable.put(this.a(v0.getKey()), v0); - this.d = HashObjObjMaps.newImmutableMap(toImmutable); - // Akarin end + this.d.put(this.a(v0.getKey()), v0); try { this.save(); @@ -111,11 +101,7 @@ public class JsonList> { } public void remove(K k0) { - // Akarin start - Map toImmutable = HashObjObjMaps.newMutableMap(this.getBackingMap()); - toImmutable.remove(this.a(k0)); - this.d = HashObjObjMaps.newImmutableMap(toImmutable); - // Akarin end + this.d.remove(this.a(k0)); try { this.save(); @@ -174,11 +160,7 @@ public class JsonList> { this.d.remove(this.a(k0)); }*/ - // Akarin start - Map toImmutable = HashObjObjMaps.newMutableMap(this.getBackingMap()); - toImmutable.values().removeIf(JsonListEntry::hasExpired); - this.d = HashObjObjMaps.newImmutableMap(toImmutable); - // Akarin end + this.getBackingMap().values().removeIf(JsonListEntry::hasExpired); // Paper end } @@ -192,7 +174,6 @@ public class JsonList> { public void save() throws IOException { this.removeStaleEntries(); // Paper - remove expired values before saving - Runnable runnable = () -> { // Akarin Collection collection = this.d.values(); String s = this.b.toJson(collection); BufferedWriter bufferedwriter = null; @@ -200,13 +181,9 @@ public class JsonList> { try { bufferedwriter = Files.newWriter(this.c, StandardCharsets.UTF_8); bufferedwriter.write(s); - } catch (IOException e) { // Akarin - Bukkit.getLogger().log(Level.SEVERE, "Failed to save {0}, {1}", new Object[] {this.c.getName(), e.getMessage()}); // Akarin } finally { IOUtils.closeQuietly(bufferedwriter); } - }; // Akarin - AkarinAsyncExecutor.scheduleSingleAsyncTask(runnable); // Akarin } @@ -219,17 +196,16 @@ public class JsonList> { Collection> collection = (Collection) ChatDeserializer.a(this.b, (Reader) bufferedreader, (Type) JsonList.f); if (collection != null) { + this.d.clear(); Iterator iterator = collection.iterator(); - Map toImmutable = HashObjObjMaps.newUpdatableMap(this.getBackingMap()); // Akarin while (iterator.hasNext()) { JsonListEntry jsonlistentry = (JsonListEntry) iterator.next(); if (jsonlistentry.getKey() != null) { - toImmutable.put(this.a((K) jsonlistentry.getKey()), (V) jsonlistentry); // CraftBukkit - fix decompile error // Akarin + this.d.put(this.a((K) jsonlistentry.getKey()), (V) jsonlistentry); // CraftBukkit - fix decompile error } } - this.d = HashObjObjMaps.newImmutableMap(toImmutable); // Akarin } // Spigot Start } catch ( com.google.gson.JsonParseException ex )