From ba1a3656a14e9b71ca4e0608eb32b808f7e8de86 Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 28 Sep 2016 23:39:00 +0200 Subject: [PATCH] You can tell whether an item already exists in the array when calling array_appendu() now. --- modules/src/data/array.c | 9 ++++++--- modules/src/data/array.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/src/data/array.c b/modules/src/data/array.c index 68fad1ff5..8943323cb 100644 --- a/modules/src/data/array.c +++ b/modules/src/data/array.c @@ -31,10 +31,13 @@ bool array_contains(void* arrayp, void* value) return false; } -void array_appendu(void* arrayp, void* value) +bool array_appendu(void* arrayp, void* value) { - if (!array_contains(arrayp, value)) - array_append(arrayp, value); + if (array_contains(arrayp, value)) + return true; + + array_append(arrayp, value); + return false; } void array_remove(void* arrayp, void* value) diff --git a/modules/src/data/array.h b/modules/src/data/array.h index 156bad1e2..601873571 100644 --- a/modules/src/data/array.h +++ b/modules/src/data/array.h @@ -18,7 +18,7 @@ struct array } extern void array_append(void* array, void* value); -extern void array_appendu(void* array, void* value); +extern bool array_appendu(void* array, void* value); extern void array_remove(void* array, void* value); extern bool array_contains(void* array, void* value);