From 22b384b2a53a8a7e6ee7c80db283ab9e044bd5ea Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 29 Mar 2023 13:02:28 +0700 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20Interner?= =?UTF-8?q?=20=D0=BE=D1=82=20guava=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D1=83=D0=B5=D1=82=D1=81=D1=8F=20Interner=20=D0=BE=D1=82?= =?UTF-8?q?=20Caffeine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt | 8 ++++---- .../dbotthepony/kstarbound/defs/IThingWithDescription.kt | 2 +- .../ru/dbotthepony/kstarbound/defs/ItemReference.kt | 2 +- .../ru/dbotthepony/kstarbound/defs/RegistryReference.kt | 5 ----- .../kstarbound/io/json/InternedJsonElementAdapter.kt | 2 +- .../kstarbound/io/json/builder/BuilderAdapter.kt | 2 +- .../kstarbound/io/json/builder/FactoryAdapter.kt | 2 +- .../io/json/factory/ImmutableCollectionAdapterFactory.kt | 2 +- .../kstarbound/io/json/factory/ImmutableMapTypeAdapter.kt | 2 +- src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt | 2 +- .../kotlin/ru/dbotthepony/kstarbound/util/PathStack.kt | 2 +- .../kotlin/ru/dbotthepony/kstarbound/util/SBPattern.kt | 4 ++-- 12 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index d74bef1c..5fdee2a5 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -2,8 +2,7 @@ package ru.dbotthepony.kstarbound import com.github.benmanes.caffeine.cache.Cache import com.github.benmanes.caffeine.cache.Caffeine -import com.google.common.collect.Interner -import com.google.common.collect.Interners +import com.github.benmanes.caffeine.cache.Interner import com.google.gson.* import com.google.gson.internal.bind.JsonTreeReader import it.unimi.dsi.fastutil.objects.Object2ObjectFunction @@ -796,11 +795,12 @@ class Starbound : ISBFileLocator { /** * Глобальный [Interner] для [String] * - * Так как нет смысла иметь множество [Interner]'ов для потенциального "больше одного" [Starbound], + * Так как нет смысла иметь множество [Interner]'ов для [String], + * а так же в силу его поточной безопасности, * данный [Interner] доступен глобально */ @JvmField - val STRINGS: Interner = Interners.newBuilder().weak().concurrencyLevel(8).build() + val STRINGS: Interner = Interner.newWeakInterner() private val polyfill by lazy { loadInternalScript("polyfill") } } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/IThingWithDescription.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/IThingWithDescription.kt index 1cb03a7a..8398dda7 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/IThingWithDescription.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/IThingWithDescription.kt @@ -1,7 +1,7 @@ package ru.dbotthepony.kstarbound.defs import com.google.common.collect.ImmutableMap -import com.google.common.collect.Interner +import com.github.benmanes.caffeine.cache.Interner import com.google.gson.Gson import com.google.gson.TypeAdapter import com.google.gson.TypeAdapterFactory diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/ItemReference.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/ItemReference.kt index 8b0d027b..e8061671 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/ItemReference.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/ItemReference.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.kstarbound.defs -import com.google.common.collect.Interner +import com.github.benmanes.caffeine.cache.Interner import com.google.gson.Gson import com.google.gson.JsonObject import com.google.gson.TypeAdapter diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/RegistryReference.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/RegistryReference.kt index e85c4a14..410a63d9 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/RegistryReference.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/RegistryReference.kt @@ -1,6 +1,5 @@ package ru.dbotthepony.kstarbound.defs -import com.google.common.collect.Interners import com.google.gson.Gson import com.google.gson.JsonSyntaxException import com.google.gson.TypeAdapter @@ -11,11 +10,7 @@ import com.google.gson.stream.JsonToken import com.google.gson.stream.JsonWriter import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap import ru.dbotthepony.kstarbound.RegistryObject -import java.lang.ref.Reference -import java.lang.ref.ReferenceQueue -import java.lang.ref.WeakReference import java.lang.reflect.ParameterizedType -import java.util.concurrent.ConcurrentHashMap import java.util.function.Supplier class RegistryReferenceFactory : TypeAdapterFactory { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/InternedJsonElementAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/InternedJsonElementAdapter.kt index 3529a7dc..6a5fd18f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/InternedJsonElementAdapter.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/InternedJsonElementAdapter.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.kstarbound.io.json -import com.google.common.collect.Interner +import com.github.benmanes.caffeine.cache.Interner import com.google.gson.JsonArray import com.google.gson.JsonElement import com.google.gson.JsonNull diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/BuilderAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/BuilderAdapter.kt index 0009368a..bb10ca5b 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/BuilderAdapter.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/BuilderAdapter.kt @@ -2,7 +2,7 @@ package ru.dbotthepony.kstarbound.io.json.builder import com.google.common.collect.ImmutableMap import com.google.common.collect.ImmutableSet -import com.google.common.collect.Interner +import com.github.benmanes.caffeine.cache.Interner import com.google.gson.Gson import com.google.gson.JsonObject import com.google.gson.JsonSyntaxException diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/FactoryAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/FactoryAdapter.kt index a0784104..bfd57aaf 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/FactoryAdapter.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/FactoryAdapter.kt @@ -2,7 +2,7 @@ package ru.dbotthepony.kstarbound.io.json.builder import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableMap -import com.google.common.collect.Interner +import com.github.benmanes.caffeine.cache.Interner import com.google.gson.Gson import com.google.gson.JsonArray import com.google.gson.JsonObject diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/factory/ImmutableCollectionAdapterFactory.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/factory/ImmutableCollectionAdapterFactory.kt index 28beb9e0..8638fbf2 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/factory/ImmutableCollectionAdapterFactory.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/factory/ImmutableCollectionAdapterFactory.kt @@ -3,7 +3,7 @@ package ru.dbotthepony.kstarbound.io.json.factory import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableMap import com.google.common.collect.ImmutableSet -import com.google.common.collect.Interner +import com.github.benmanes.caffeine.cache.Interner import com.google.gson.Gson import com.google.gson.TypeAdapter import com.google.gson.TypeAdapterFactory diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/factory/ImmutableMapTypeAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/factory/ImmutableMapTypeAdapter.kt index e6b02f7b..b6b443f0 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/factory/ImmutableMapTypeAdapter.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/factory/ImmutableMapTypeAdapter.kt @@ -2,7 +2,7 @@ package ru.dbotthepony.kstarbound.io.json.factory import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableMap -import com.google.common.collect.Interner +import com.github.benmanes.caffeine.cache.Interner import com.google.gson.JsonSyntaxException import com.google.gson.TypeAdapter import com.google.gson.stream.JsonReader diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt index a7b557f1..47e65234 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.kstarbound.lua -import com.google.common.collect.Interner +import com.github.benmanes.caffeine.cache.Interner import com.google.gson.JsonArray import com.google.gson.JsonElement import com.google.gson.JsonNull diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/PathStack.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/PathStack.kt index f8bfd429..eeafbe4f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/PathStack.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/util/PathStack.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.kstarbound.util -import com.google.common.collect.Interner +import com.github.benmanes.caffeine.cache.Interner import kotlin.concurrent.getOrSet class PathStack(private val interner: Interner = Interner { it }) { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/SBPattern.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/SBPattern.kt index 2e0408c3..bc4f721d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/SBPattern.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/util/SBPattern.kt @@ -1,9 +1,9 @@ package ru.dbotthepony.kstarbound.util +import com.github.benmanes.caffeine.cache.Interner import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableMap import com.google.common.collect.ImmutableSet -import com.google.common.collect.Interners import com.google.gson.Gson import com.google.gson.TypeAdapter import com.google.gson.TypeAdapterFactory @@ -115,7 +115,7 @@ class SBPattern private constructor( } companion object : TypeAdapterFactory { - private val interner = Interners.newWeakInterner() + private val interner: Interner = Interner.newWeakInterner() @JvmField val EMPTY = raw("")