From 6aca9d40f1dadfb66e944c97af643c0dedcccf02 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 6 Feb 2023 18:20:57 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BD=D1=82=D0=B5=D1=80=D0=BD=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=D1=86=D0=B8=D1=8F=20sbpattern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/dbotthepony/kstarbound/util/SBPattern.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 }