Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jvp_object_contains: remove unnecessary jv_copy #2937

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,23 @@ BINOPS

static jv type_error(jv bad, const char* msg) {
char errbuf[15];
jv err = jv_invalid_with_msg(jv_string_fmt("%s (%s) %s",
jv_kind_name(jv_get_kind(bad)),
jv_dump_string_trunc(jv_copy(bad), errbuf, sizeof(errbuf)),
const char *badkind = jv_kind_name(jv_get_kind(bad));
nicowilliams marked this conversation as resolved.
Show resolved Hide resolved
jv err = jv_invalid_with_msg(jv_string_fmt("%s (%s) %s", badkind,
jv_dump_string_trunc(bad, errbuf, sizeof(errbuf)),
msg));
jv_free(bad);
return err;
}

static jv type_error2(jv bad1, jv bad2, const char* msg) {
char errbuf1[15],errbuf2[15];
const char *badkind1 = jv_kind_name(jv_get_kind(bad1));
const char *badkind2 = jv_kind_name(jv_get_kind(bad2));
jv err = jv_invalid_with_msg(jv_string_fmt("%s (%s) and %s (%s) %s",
jv_kind_name(jv_get_kind(bad1)),
jv_dump_string_trunc(jv_copy(bad1), errbuf1, sizeof(errbuf1)),
jv_kind_name(jv_get_kind(bad2)),
jv_dump_string_trunc(jv_copy(bad2), errbuf2, sizeof(errbuf2)),
emanuele6 marked this conversation as resolved.
Show resolved Hide resolved
badkind1,
jv_dump_string_trunc(bad1, errbuf1, sizeof(errbuf1)),
badkind2,
jv_dump_string_trunc(bad2, errbuf2, sizeof(errbuf2)),
msg));
jv_free(bad1);
jv_free(bad2);
return err;
}

Expand Down Expand Up @@ -283,7 +282,7 @@ static jv f_endswith(jq_state *jq, jv a, jv b) {
const char *bstr = jv_string_value(b);
size_t alen = jv_string_length_bytes(jv_copy(a));
size_t blen = jv_string_length_bytes(jv_copy(b));
jv ret;;
jv ret;

if (alen < blen ||
memcmp(astr + (alen - blen), bstr, blen) != 0)
Expand Down
3 changes: 1 addition & 2 deletions src/jv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1729,10 +1729,9 @@ static int jvp_object_contains(jv a, jv b) {
int r = 1;

jv_object_foreach(b, key, b_val) {
jv a_val = jv_object_get(jv_copy(a), jv_copy(key));
jv a_val = jv_object_get(jv_copy(a), key);

r = jv_contains(a_val, b_val);
jv_free(key);

if (!r) break;
}
Expand Down