Skip to content

Commit

Permalink
Merge pull request #1823 from square/jw.no-allocate.2024-03-11
Browse files Browse the repository at this point in the history
Do not allocate path outside conditionals
  • Loading branch information
JakeWharton committed Mar 21, 2024
2 parents c5f3b36 + 7d51df5 commit 8ca4f8b
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8ca4f8b

Please sign in to comment.