Skip to content

Commit

Permalink
Remove unnecessary recursions caused by type reference by name.
Browse files Browse the repository at this point in the history
  • Loading branch information
PengZheng committed Jan 18, 2024
1 parent 88d43dd commit 927926c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
7 changes: 3 additions & 4 deletions libs/dfi/src/dyn_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,10 @@ static void dynType_deepFree(const dyn_type* type, void* loc, bool alsoDeleteSel
if (loc != NULL) {
const dyn_type* subType = NULL;
char* text = NULL;
while (type->type == DYN_TYPE_REF) {
type = type->ref.ref;
}
switch (type->type) {
case DYN_TYPE_REF:
//NOTE: do not recursively forward asloDeleteSelf, because this is already handled in this function)
dynType_deepFree(type->ref.ref, loc, false);
break;
case DYN_TYPE_COMPLEX :
dynType_freeComplexType(type, loc);
break;
Expand Down
24 changes: 11 additions & 13 deletions libs/dfi/src/json_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ int jsonSerializer_deserialize(const dyn_type* type, const char* input, size_t l
}

int jsonSerializer_deserializeJson(const dyn_type* type, json_t* input, void** out) {
return jsonSerializer_createType(type, input, out);
const dyn_type* real = type;
while (real->type == DYN_TYPE_REF) {
real = real->ref.ref;
}
return jsonSerializer_createType(real, input, out);
}

static int jsonSerializer_createType(const dyn_type* type, json_t* val, void** result) {
Expand Down Expand Up @@ -203,10 +207,7 @@ static int jsonSerializer_parseAny(const dyn_type* type, void* loc, json_t* val)
celix_err_pushf("Error cannot deserialize pointer to pointer");
}
break;
case 'l':
status = jsonSerializer_parseAny(type->ref.ref, loc, val);
break;
case 'P' :
//case 'P' :
default :
status = ERROR;
celix_err_pushf("Error provided type '%c' not supported for JSON\n", c);
Expand Down Expand Up @@ -273,7 +274,11 @@ static int jsonSerializer_parseEnum(const dyn_type* type, const char* enum_name,
}

int jsonSerializer_serializeJson(const dyn_type* type, const void* input, json_t** out) {
return jsonSerializer_writeAny(type, (void*)input /*TODO update static function to take const void**/, out);
const dyn_type* real = type;
while (real->type == DYN_TYPE_REF) {
real = real->ref.ref;
}
return jsonSerializer_writeAny(real, (void*)input /*TODO update static function to take const void**/, out);
}

static int jsonSerializer_writeAny(const dyn_type *type, void* input, json_t **out) {
Expand Down Expand Up @@ -363,13 +368,6 @@ static int jsonSerializer_writeAny(const dyn_type *type, void* input, json_t **o
case '[' :
status = jsonSerializer_writeSequence(type, input, &val);
break;
case 'P' :
status = ERROR;
celix_err_pushf("Untyped pointer not supported for serialization.");
break;
case 'l':
status = jsonSerializer_writeAny(type->ref.ref, input, out);
break;
default :
celix_err_pushf("Unsupported descriptor '%c'", descriptor);
status = ERROR;
Expand Down

0 comments on commit 927926c

Please sign in to comment.