From 0b03ab854eecafc443e4702a54aed43ec75cc1a8 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 11 Jan 2018 07:29:34 +0100 Subject: [PATCH] Avoid unnecessary casts in the JSON encoder --- lib/base/json.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/base/json.cpp b/lib/base/json.cpp index ff9f04c49..c074aed56 100644 --- a/lib/base/json.cpp +++ b/lib/base/json.cpp @@ -81,12 +81,24 @@ static void Encode(yajl_gen handle, const Value& value) break; case ValueObject: - if (value.IsObjectType()) - EncodeDictionary(handle, value); - else if (value.IsObjectType()) - EncodeArray(handle, value); - else - yajl_gen_null(handle); + { + const Object::Ptr& obj = value.Get(); + Dictionary::Ptr dict = dynamic_pointer_cast(obj); + + if (dict) { + EncodeDictionary(handle, dict); + break; + } + + Array::Ptr arr = dynamic_pointer_cast(obj); + + if (arr) { + EncodeArray(handle, arr); + break; + } + } + + yajl_gen_null(handle); break; case ValueEmpty: