MINOR: pattern: make pat_ref_add() rely on pat_ref_append()
Let's remove unneeded code duplication, both are exactly the same.
diff --git a/src/pattern.c b/src/pattern.c
index cdacefb..0890fb2 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -1982,9 +1982,9 @@
return 1;
}
-/* This function adds entry to <ref>. It can failed with memory error. The new
+/* This function adds entry to <ref>. It can fail on memory error. The new
* entry is added at all the pattern_expr registered in this reference. The
- * function stop on the first error encountered. It returns 0 and err is
+ * function stops on the first error encountered. It returns 0 and <err> is
* filled. If an error is encountered, the complete add operation is cancelled.
* If the insertion is a success the function returns 1.
*/
@@ -1995,36 +1995,12 @@
struct pat_ref_elt *elt;
struct pattern_expr *expr;
- elt = malloc(sizeof(*elt));
+ elt = pat_ref_append(ref, pattern, sample, -1);
if (!elt) {
memprintf(err, "out of memory error");
return 0;
}
- elt->line = -1;
-
- elt->pattern = strdup(pattern);
- if (!elt->pattern) {
- free(elt);
- memprintf(err, "out of memory error");
- return 0;
- }
-
- if (sample) {
- elt->sample = strdup(sample);
- if (!elt->sample) {
- free(elt->pattern);
- free(elt);
- memprintf(err, "out of memory error");
- return 0;
- }
- }
- else
- elt->sample = NULL;
-
- LIST_INIT(&elt->back_refs);
- LIST_ADDQ(&ref->head, &elt->list);
-
list_for_each_entry(expr, &ref->pat, list) {
if (!pat_ref_push(elt, expr, 0, err)) {
/* If the insertion fails, try to delete all the added entries. */
@@ -2032,7 +2008,6 @@
return 0;
}
}
-
return 1;
}