Skip to content

Commit

Permalink
Do not allocate path outside conditionals
Browse files Browse the repository at this point in the history
It is not guaranteed to be used at this point and performs a decent amount of allocation and computation.
  • Loading branch information
JakeWharton committed Mar 11, 2024
1 parent be6cd87 commit 7d51df5
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 7d51df5

Please sign in to comment.