mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
Merge pull request #1823 from square/jw.no-allocate.2024-03-11
Do not allocate path outside conditionals
This commit is contained in:
@@ -74,16 +74,15 @@ public class EnumJsonAdapter<T : Enum<T>> internal constructor(
|
|||||||
override fun fromJson(reader: JsonReader): T? {
|
override fun fromJson(reader: JsonReader): T? {
|
||||||
val index = reader.selectString(options)
|
val index = reader.selectString(options)
|
||||||
if (index != -1) return constants[index]
|
if (index != -1) return constants[index]
|
||||||
val path = reader.path
|
|
||||||
if (!useFallbackValue) {
|
if (!useFallbackValue) {
|
||||||
val name = reader.nextString()
|
val name = reader.nextString()
|
||||||
throw JsonDataException(
|
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) {
|
if (reader.peek() != STRING) {
|
||||||
throw JsonDataException(
|
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()
|
reader.skipValue()
|
||||||
|
Reference in New Issue
Block a user