From: Stephen Roantree Date: Thu, 25 Oct 2012 13:29:23 +0000 (-0700) Subject: Remove redundant code from jv_object_contains X-Git-Tag: jq-1.2~35^2^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1b556315afdafde27a935f711efe212d2d988842;p=jq Remove redundant code from jv_object_contains --- diff --git a/jv.c b/jv.c index 45df882..77937a8 100644 --- a/jv.c +++ b/jv.c @@ -890,33 +890,17 @@ int jv_object_contains(jv a, jv b) { assert(jv_get_kind(b) == JV_KIND_OBJECT); int r = 1; - int nkeys = jv_object_length(jv_copy(b)); - jv* keys = malloc(sizeof(jv) * nkeys); - int kidx = 0; jv_object_foreach(i, b) { - keys[kidx++] = jv_object_iter_key(b, i); - } - - for (int i=0; i < nkeys; i++) { - jv a_val = jv_object_get(jv_copy(a), jv_copy(keys[i])); - jv b_val = jv_object_get(jv_copy(b), jv_copy(keys[i])); + jv key = jv_object_iter_key(b, i); + jv a_val = jv_object_get(jv_copy(a), jv_copy(key)); + jv b_val = jv_object_get(jv_copy(b), jv_copy(key)); - if (!(jv_get_kind(a_val) == jv_get_kind(b_val) - && jv_contains(jv_copy(a_val), jv_copy(b_val)))) { - r = 0; - } - - jv_free(a_val); - jv_free(b_val); + r = jv_contains(a_val, b_val); + jv_free(key); if (!r) break; } - for (int i=0; i < nkeys; i++) { - jv_free(keys[i]); - } - free(keys); - jv_free(a); jv_free(b); return r;