diff options
| author | 2020-06-07 21:48:10 -0700 | |
|---|---|---|
| committer | 2020-11-24 01:06:31 +0100 | |
| commit | 9f60cdd76b6044931cc2f2b6f2fbec3deb67a425 (patch) | |
| tree | 66c1a3c42769535966367c3f6f10881da2673f33 /src/plist.c | |
| parent | 2899553df92cd4e10590da73ae7375e5b5517d45 (diff) | |
| download | libplist-9f60cdd76b6044931cc2f2b6f2fbec3deb67a425.tar.gz libplist-9f60cdd76b6044931cc2f2b6f2fbec3deb67a425.tar.bz2 | |
Improve code readability by not using else after return
[clang-tidy] Found with readability-else-after-return
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Diffstat (limited to 'src/plist.c')
| -rw-r--r-- | src/plist.c | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/src/plist.c b/src/plist.c index 57f0be4..4d327e0 100644 --- a/src/plist.c +++ b/src/plist.c | |||
| @@ -516,12 +516,11 @@ PLIST_API void plist_array_set_item(plist_t node, plist_t item, uint32_t n) | |||
| 516 | assert(idx >= 0); | 516 | assert(idx >= 0); |
| 517 | if (idx < 0) { | 517 | if (idx < 0) { |
| 518 | return; | 518 | return; |
| 519 | } else { | 519 | } |
| 520 | node_insert(node, idx, item); | 520 | node_insert(node, idx, item); |
| 521 | ptrarray_t* pa = ((plist_data_t)((node_t*)node)->data)->hashtable; | 521 | ptrarray_t* pa = ((plist_data_t)((node_t*)node)->data)->hashtable; |
| 522 | if (pa) { | 522 | if (pa) { |
| 523 | ptr_array_set(pa, item, idx); | 523 | ptr_array_set(pa, item, idx); |
| 524 | } | ||
| 525 | } | 524 | } |
| 526 | } | 525 | } |
| 527 | } | 526 | } |
| @@ -714,9 +713,8 @@ PLIST_API void plist_dict_set_item(plist_t node, const char* key, plist_t item) | |||
| 714 | assert(idx >= 0); | 713 | assert(idx >= 0); |
| 715 | if (idx < 0) { | 714 | if (idx < 0) { |
| 716 | return; | 715 | return; |
| 717 | } else { | ||
| 718 | node_insert(node, idx, item); | ||
| 719 | } | 716 | } |
| 717 | node_insert(node, idx, item); | ||
| 720 | key_node = node_prev_sibling(item); | 718 | key_node = node_prev_sibling(item); |
| 721 | } else { | 719 | } else { |
| 722 | key_node = plist_new_key(key); | 720 | key_node = plist_new_key(key); |
| @@ -1038,33 +1036,22 @@ int plist_data_compare(const void *a, const void *b) | |||
| 1038 | case PLIST_UID: | 1036 | case PLIST_UID: |
| 1039 | if (val_a->length != val_b->length) | 1037 | if (val_a->length != val_b->length) |
| 1040 | return FALSE; | 1038 | return FALSE; |
| 1041 | if (val_a->intval == val_b->intval) //it is an union so this is sufficient | 1039 | return val_a->intval == val_b->intval; //it is an union so this is sufficient |
| 1042 | return TRUE; | ||
| 1043 | else | ||
| 1044 | return FALSE; | ||
| 1045 | 1040 | ||
| 1046 | case PLIST_KEY: | 1041 | case PLIST_KEY: |
| 1047 | case PLIST_STRING: | 1042 | case PLIST_STRING: |
| 1048 | if (!strcmp(val_a->strval, val_b->strval)) | 1043 | return strcmp(val_a->strval, val_b->strval) == 0; |
| 1049 | return TRUE; | ||
| 1050 | else | ||
| 1051 | return FALSE; | ||
| 1052 | 1044 | ||
| 1053 | case PLIST_DATA: | 1045 | case PLIST_DATA: |
| 1054 | if (val_a->length != val_b->length) | 1046 | if (val_a->length != val_b->length) |
| 1055 | return FALSE; | 1047 | return FALSE; |
| 1056 | if (!memcmp(val_a->buff, val_b->buff, val_a->length)) | 1048 | return memcmp(val_a->buff, val_b->buff, val_a->length) == 0; |
| 1057 | return TRUE; | 1049 | |
| 1058 | else | ||
| 1059 | return FALSE; | ||
| 1060 | case PLIST_ARRAY: | 1050 | case PLIST_ARRAY: |
| 1061 | case PLIST_DICT: | 1051 | case PLIST_DICT: |
| 1062 | //compare pointer | 1052 | //compare pointer |
| 1063 | if (a == b) | 1053 | return a == b; |
| 1064 | return TRUE; | 1054 | |
| 1065 | else | ||
| 1066 | return FALSE; | ||
| 1067 | break; | ||
| 1068 | default: | 1055 | default: |
| 1069 | break; | 1056 | break; |
| 1070 | } | 1057 | } |
| @@ -1195,11 +1182,13 @@ PLIST_API int plist_uint_val_compare(plist_t uintnode, uint64_t cmpval) | |||
| 1195 | plist_get_uint_val(uintnode, &uintval); | 1182 | plist_get_uint_val(uintnode, &uintval); |
| 1196 | if (uintval == cmpval) { | 1183 | if (uintval == cmpval) { |
| 1197 | return 0; | 1184 | return 0; |
| 1198 | } else if (uintval < cmpval) { | 1185 | } |
| 1186 | |||
| 1187 | if (uintval < cmpval) { | ||
| 1199 | return -1; | 1188 | return -1; |
| 1200 | } else { | ||
| 1201 | return 1; | ||
| 1202 | } | 1189 | } |
| 1190 | |||
| 1191 | return 1; | ||
| 1203 | } | 1192 | } |
| 1204 | 1193 | ||
| 1205 | PLIST_API int plist_uid_val_compare(plist_t uidnode, uint64_t cmpval) | 1194 | PLIST_API int plist_uid_val_compare(plist_t uidnode, uint64_t cmpval) |
| @@ -1211,11 +1200,13 @@ PLIST_API int plist_uid_val_compare(plist_t uidnode, uint64_t cmpval) | |||
| 1211 | plist_get_uid_val(uidnode, &uidval); | 1200 | plist_get_uid_val(uidnode, &uidval); |
| 1212 | if (uidval == cmpval) { | 1201 | if (uidval == cmpval) { |
| 1213 | return 0; | 1202 | return 0; |
| 1214 | } else if (uidval < cmpval) { | 1203 | } |
| 1204 | |||
| 1205 | if (uidval < cmpval) { | ||
| 1215 | return -1; | 1206 | return -1; |
| 1216 | } else { | ||
| 1217 | return 1; | ||
| 1218 | } | 1207 | } |
| 1208 | |||
| 1209 | return 1; | ||
| 1219 | } | 1210 | } |
| 1220 | 1211 | ||
| 1221 | PLIST_API int plist_real_val_compare(plist_t realnode, double cmpval) | 1212 | PLIST_API int plist_real_val_compare(plist_t realnode, double cmpval) |
| @@ -1231,16 +1222,22 @@ PLIST_API int plist_real_val_compare(plist_t realnode, double cmpval) | |||
| 1231 | double diff = fabs(a - b); | 1222 | double diff = fabs(a - b); |
| 1232 | if (a == b) { | 1223 | if (a == b) { |
| 1233 | return 0; | 1224 | return 0; |
| 1234 | } else if (a == 0 || b == 0 || (abs_a + abs_b < DBL_MIN)) { | 1225 | } |
| 1226 | |||
| 1227 | if (a == 0 || b == 0 || (abs_a + abs_b < DBL_MIN)) { | ||
| 1235 | if (diff < (DBL_EPSILON * DBL_MIN)) { | 1228 | if (diff < (DBL_EPSILON * DBL_MIN)) { |
| 1236 | return 0; | 1229 | return 0; |
| 1237 | } else if (a < b) { | 1230 | } |
| 1231 | |||
| 1232 | if (a < b) { | ||
| 1238 | return -1; | 1233 | return -1; |
| 1239 | } | 1234 | } |
| 1240 | } else { | 1235 | } else { |
| 1241 | if ((diff / fmin(abs_a + abs_b, DBL_MAX)) < DBL_EPSILON) { | 1236 | if ((diff / fmin(abs_a + abs_b, DBL_MAX)) < DBL_EPSILON) { |
| 1242 | return 0; | 1237 | return 0; |
| 1243 | } else if (a < b) { | 1238 | } |
| 1239 | |||
| 1240 | if (a < b) { | ||
| 1244 | return -1; | 1241 | return -1; |
| 1245 | } | 1242 | } |
| 1246 | } | 1243 | } |
| @@ -1259,11 +1256,13 @@ PLIST_API int plist_date_val_compare(plist_t datenode, int32_t cmpsec, int32_t c | |||
| 1259 | uint64_t cmpval = ((int64_t)cmpsec << 32) | cmpusec; | 1256 | uint64_t cmpval = ((int64_t)cmpsec << 32) | cmpusec; |
| 1260 | if (dateval == cmpval) { | 1257 | if (dateval == cmpval) { |
| 1261 | return 0; | 1258 | return 0; |
| 1262 | } else if (dateval < cmpval) { | 1259 | } |
| 1260 | |||
| 1261 | if (dateval < cmpval) { | ||
| 1263 | return -1; | 1262 | return -1; |
| 1264 | } else { | ||
| 1265 | return 1; | ||
| 1266 | } | 1263 | } |
| 1264 | |||
| 1265 | return 1; | ||
| 1267 | } | 1266 | } |
| 1268 | 1267 | ||
| 1269 | PLIST_API int plist_string_val_compare(plist_t strnode, const char* cmpval) | 1268 | PLIST_API int plist_string_val_compare(plist_t strnode, const char* cmpval) |
| @@ -1328,9 +1327,12 @@ PLIST_API int plist_data_val_compare(plist_t datanode, const uint8_t* cmpval, si | |||
| 1328 | plist_data_t data = plist_get_data(datanode); | 1327 | plist_data_t data = plist_get_data(datanode); |
| 1329 | if (data->length < n) { | 1328 | if (data->length < n) { |
| 1330 | return -1; | 1329 | return -1; |
| 1331 | } else if (data->length > n) { | 1330 | } |
| 1331 | |||
| 1332 | if (data->length > n) { | ||
| 1332 | return 1; | 1333 | return 1; |
| 1333 | } | 1334 | } |
| 1335 | |||
| 1334 | return memcmp(data->buff, cmpval, n); | 1336 | return memcmp(data->buff, cmpval, n); |
| 1335 | } | 1337 | } |
| 1336 | 1338 | ||
