changeset 1087:5bf62a7209ab

post: use sexpr_for_each instead of (poorly) open-coding it Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Thu, 31 Aug 2017 16:23:59 +0300
parents ab03d4068049
children f8bf32720459
files post.c
diffstat 1 files changed, 8 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/post.c	Wed Aug 30 16:06:19 2017 +0300
+++ b/post.c	Thu Aug 31 16:23:59 2017 +0300
@@ -93,23 +93,18 @@
 
 static void post_add_tags(avl_tree_t *taglist, struct val *list)
 {
-	struct post_tag *tag;
-
-	/* tags list not present in metadata */
-	if (!list)
-		return;
+	struct val *tagval;
+	struct val *tmp;
 
-	for (; list; list = sexpr_cdr(list)) {
-		struct val *tagval;
+	sexpr_for_each(tagval, tmp, list) {
+		struct post_tag *tag;
 		struct str *tagname;
 
-		tagval = sexpr_car(val_getref(list));
-
 		/* sanity check */
 		ASSERT3U(tagval->type, ==, VT_STR);
 
 		/* get the tag name */
-		tagname = val_cast_to_str(tagval);
+		tagname = val_getref_str(tagval);
 
 		tag = malloc(sizeof(struct post_tag));
 		ASSERT(tag);
@@ -210,22 +205,15 @@
 
 static void post_add_comments(struct post *post, struct val *list)
 {
-	if (!list)
-		return;
+	struct val *val;
+	struct val *tmp;
 
-	for (; list; list = sexpr_cdr(list)) {
-		struct val *val;
-
-		val = sexpr_car(val_getref(list));
-
+	sexpr_for_each(val, tmp, list) {
 		/* sanity check */
 		ASSERT3U(val->type, ==, VT_INT);
 
 		/* add the comment */
 		post_add_comment(post, val->i);
-
-		/* release the value */
-		val_putref(val);
 	}
 }