Skip to content

Commit

Permalink
change jv_clone to jv_unshare
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxBrandtner committed May 3, 2024
1 parent c43ae93 commit 29b398f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/jq_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ static void jv_test() {
}

{
jv output = jv_clone(jv_parse("{\"test\":[{\"some\":\"value\"}, 1, true, false, null]}"));
jv output = jv_unshare(jv_parse("{\"test\":[{\"some\":\"value\"}, 1, true, false, null]}"));

jv_free(output);
}
Expand Down
8 changes: 4 additions & 4 deletions src/jv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1862,14 +1862,14 @@ jv jv_object_iter_value(jv object, int iter) {
/*
* Memory management
*/
jv jv_clone(jv input){
jv jv_unshare(jv input){
switch(jv_get_kind(input)){
case JV_KIND_INVALID:
if(!jv_invalid_has_msg(jv_copy(input))){
jv_free(input);
return jv_invalid();
}
return jv_invalid_with_msg(jv_clone(jv_invalid_get_msg(jv_copy(input))));
return jv_invalid_with_msg(jv_unshare(jv_invalid_get_msg(jv_copy(input))));
case JV_KIND_OBJECT:
case JV_KIND_ARRAY:
{
Expand All @@ -1884,11 +1884,11 @@ jv jv_clone(jv input){
}

for(size_t i = 0; i < keys_length; i++){
jv key = JV_ARRAY(jv_clone(jv_array_get(jv_copy(keys), i)));
jv key = JV_ARRAY(jv_unshare(jv_array_get(jv_copy(keys), i)));

output_object = jv_setpath(
output_object,key,
jv_clone(
jv_unshare(
jv_getpath(jv_copy(output_object), jv_copy(key))
)
);
Expand Down
4 changes: 2 additions & 2 deletions src/jv.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jv_kind jv_get_kind(jv);
const char* jv_kind_name(jv_kind);
static int jv_is_valid(jv x) { return jv_get_kind(x) != JV_KIND_INVALID; }

//jv_clone() creates a deep copy of the input aka the content of the output will be identical to the input, but no shared memory exists between them
jv jv_clone(jv);
//jv_unshare() creates a deep copy of the input aka the content of the output will be identical to the input, but no shared memory exists between them
jv jv_unshare(jv);
jv jv_copy(jv);
void jv_free(jv);

Expand Down

0 comments on commit 29b398f

Please sign in to comment.