diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/SBPattern.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/SBPattern.kt index 217be2ad..c60d4ee2 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/SBPattern.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/util/SBPattern.kt @@ -3,6 +3,7 @@ package ru.dbotthepony.kstarbound.util 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 @@ -102,6 +103,7 @@ class SBPattern private constructor( override fun create(gson: Gson, type: TypeToken): TypeAdapter? { if (type.rawType == SBPattern::class.java) { return object : TypeAdapter() { + private val interner = Interners.newWeakInterner() private val strings = gson.getAdapter(String::class.java) override fun write(out: JsonWriter, value: SBPattern?) { @@ -109,7 +111,7 @@ class SBPattern private constructor( } override fun read(`in`: JsonReader): SBPattern? { - return of(strings.read(`in`) ?: return null) + return interner.intern(of(strings.read(`in`) ?: return null)) } } as TypeAdapter }