Skip to content

Commit

Permalink
jv_array_indexes: remove a bunch of unnecessary copies/gets
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuele6 committed Mar 28, 2024
1 parent 22a03e9 commit 9c70712
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/jv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,14 +1025,13 @@ jv jv_array_slice(jv a, int start, int end) {
jv jv_array_indexes(jv a, jv b) {
jv res = jv_array();
int idx = -1;
jv_array_foreach(a, ai, aelem) {
jv_free(aelem);
int alen = jv_array_length(jv_copy(a));
for (int ai = 0; ai < alen; ++ai) {
jv_array_foreach(b, bi, belem) {
if (!jv_equal(jv_array_get(jv_copy(a), ai + bi), jv_copy(belem)))
if (!jv_equal(jv_array_get(jv_copy(a), ai + bi), belem))
idx = -1;
else if (bi == 0 && idx == -1)
idx = ai;
jv_free(belem);
}
if (idx > -1)
res = jv_array_append(res, jv_number(idx));
Expand Down

0 comments on commit 9c70712

Please sign in to comment.