Revert "Improve performance for isOp and more"

This reverts commit 17e0e3edca.
This commit is contained in:
Sotr
2019-04-10 03:46:22 +08:00
parent 9850358e29
commit 18cd8f67cb

View File

@@ -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<K, V extends JsonListEntry<K>> {
protected final Gson b;
private final File c;
// Paper - replace HashMap is ConcurrentHashMap
protected Map<String, V> d = Collections.emptyMap(); private final Map<String, V> getBackingMap() { return this.d; } // Paper - OBFHELPER // Akarin
protected final Map<String, V> d = Maps.newConcurrentMap(); private final Map<String, V> 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<K, V extends JsonListEntry<K>> {
}
public void add(V v0) {
// Akarin start
Map<String, V> 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<K, V extends JsonListEntry<K>> {
}
public void remove(K k0) {
// Akarin start
Map<String, V> 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<K, V extends JsonListEntry<K>> {
this.d.remove(this.a(k0));
}*/
// Akarin start
Map<String, V> 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<K, V extends JsonListEntry<K>> {
public void save() throws IOException {
this.removeStaleEntries(); // Paper - remove expired values before saving
Runnable runnable = () -> { // Akarin
Collection<V> collection = this.d.values();
String s = this.b.toJson(collection);
BufferedWriter bufferedwriter = null;
@@ -200,13 +181,9 @@ public class JsonList<K, V extends JsonListEntry<K>> {
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<K, V extends JsonListEntry<K>> {
Collection<JsonListEntry<K>> collection = (Collection) ChatDeserializer.a(this.b, (Reader) bufferedreader, (Type) JsonList.f);
if (collection != null) {
this.d.clear();
Iterator iterator = collection.iterator();
Map<String, V> toImmutable = HashObjObjMaps.newUpdatableMap(this.getBackingMap()); // Akarin
while (iterator.hasNext()) {
JsonListEntry<K> 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 )