From 9b7d7a76f35f293d25511540d4050eaf129c9acb Mon Sep 17 00:00:00 2001 From: Nikita Ogorodnikov Date: Fri, 30 Sep 2022 16:09:46 +0200 Subject: [PATCH] Minor performance optimization during serialization into JSON format --- .../com/datadog/android/core/internal/utils/MiscUtils.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/utils/MiscUtils.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/utils/MiscUtils.kt index e94a74c27c..bed133f264 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/utils/MiscUtils.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/utils/MiscUtils.kt @@ -60,10 +60,11 @@ internal fun Any?.toJsonElement(): JsonElement { is Double -> JsonPrimitive(this) is String -> JsonPrimitive(this) is Date -> JsonPrimitive(this.time) + // this line should come before Iterable, otherwise this branch is never executed + is JsonArray -> this is Iterable<*> -> this.toJsonArray() is Map<*, *> -> this.toJsonObject() is JsonObject -> this - is JsonArray -> this is JsonPrimitive -> this is JSONObject -> this.toJsonObject() is JSONArray -> this.toJsonArray()