Merge pull request #1823 from square/jw.no-allocate.2024-03-11

Do not allocate path outside conditionals
This commit is contained in:
Jake Wharton
2024-03-20 20:18:51 -04:00
committed by GitHub

View File

@@ -74,16 +74,15 @@ public class EnumJsonAdapter<T : Enum<T>> internal constructor(
override fun fromJson(reader: JsonReader): T? {
val index = reader.selectString(options)
if (index != -1) return constants[index]
val path = reader.path
if (!useFallbackValue) {
val name = reader.nextString()
throw JsonDataException(
"Expected one of ${nameStrings.toList()} but was $name at path $path",
"Expected one of ${nameStrings.toList()} but was $name at path ${reader.path}",
)
}
if (reader.peek() != STRING) {
throw JsonDataException(
"Expected a string but was ${reader.peek()} at path $path",
"Expected a string but was ${reader.peek()} at path ${reader.path}",
)
}
reader.skipValue()