From be996fed5258d70a9f34ecbae1d7aea74f91cfa1 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Fri, 6 Jun 2008 16:52:19 -0400 Subject: - drop attempts to keep track of visited IDs, it didn't make sense to do it that way --- src/map.c | 100 ++++---------------------------------------------------------- 1 file changed, 6 insertions(+), 94 deletions(-) (limited to 'src/map.c') diff --git a/src/map.c b/src/map.c index 51f47d7..a009571 100644 --- a/src/map.c +++ b/src/map.c @@ -61,9 +61,8 @@ struct { * list. */ struct map_entry *prev, *next; /* The name of the backend entry for this - * entry, and the names of others which - * contributed to the value. */ - char *id, **related_ids; + * entry. */ + char *id; /* Key and value. */ char *key; unsigned int key_len; @@ -199,74 +198,12 @@ map_data_find_map_entry_id(struct plugin_state *state, return entry ? *entry : NULL; } -/* Handlers for the list of related IDs. On this side we actually store them - * as one contiguous chunk of memory. */ -static bool_t -map_id_in_id_list(const char *id, char **id_list) -{ - while ((*id_list) != NULL) { - if (strcmp(id, (*id_list)) == 0) { - return TRUE; - } - id_list++; - } - return FALSE; -} - -/* Duplicate a passed-in list of strings. The result is stored in one chunk of - * memory: pointers first, then the individual strings. */ -static char ** -map_id_dup_id_list(const char **in_id_list) -{ - int i, l; - char **ret, *s; - /* Handle the NULL case. */ - if (in_id_list == NULL) { - return NULL; - } - /* Count the amount of space needed for the strings. */ - for (i = 0, l = 0; (in_id_list[i] != NULL); i++) { - l += (strlen(in_id_list[i]) + 1); - } - /* No strings = no list. */ - if (i == 0) { - return NULL; - } - /* Allocate space for the array of pointers (with NULL terminator) and - * then the string data. */ - ret = malloc((i + 1) * sizeof(char *) + l); - if (ret != NULL) { - /* Figure out where the string data will start. */ - s = (char *) &ret[i + 1]; - for (i = 0; (in_id_list[i] != NULL); i++) { - /* Set the address of this string, copy the data - * around, and then prepare the address of the next - * string. */ - ret[i] = s; - strcpy(s, in_id_list[i]); - s += (strlen(s) + 1); - } - /* NULL-terminate the array. */ - ret[i] = NULL; - } - return ret; -} - -/* Free the list -- since it's one chunk of memory, we shouldn't try anything - * complicated. */ -static void -map_id_free_id_list(char **id_list) -{ - free(id_list); -} - /* Iterate through every entry in every map, calling the callback if "all" is - * true, or if "id" is not NULL and matches the entry's ID, or if the - * "related_id" is not NULL and in the list of related IDs. If the callback + * true, or if "id" is not NULL and matches the entry's ID. If the callback * returns FALSE, then we abort and return FALSE, otherwise we return TRUE. */ static bool_t map_data_foreach_entry(struct plugin_state *state, - bool_t all, const char *id, const char *related_id, + bool_t all, const char *id, bool_t (*fn)(const char *domain, const char *map, const char *key, unsigned int key_len, const char *value, unsigned int value_len, @@ -286,10 +223,7 @@ map_data_foreach_entry(struct plugin_state *state, entry = entry->next) { if (all || ((id != NULL) && - (strcmp(id, entry->id) == 0)) || - ((related_id != NULL) && - (map_id_in_id_list(related_id, - entry->related_ids)))) { + (strcmp(id, entry->id) == 0))) { if (!(*fn)(domain->name, map->name, entry->key, entry->key_len, @@ -316,24 +250,7 @@ map_data_foreach_entry_id(struct plugin_state *state, const char *id, const char *id, void *cbdata), void *cbdata) { - return map_data_foreach_entry(state, FALSE, id, NULL, fn, cbdata); -} - -/* Iterate over every entry which lists the ID as a related ID. */ -bool_t -map_data_foreach_entry_related_id(struct plugin_state *state, - const char *related_id, - bool_t (*fn)(const char *domain, - const char *map, - const char *key, - unsigned int key_len, - const char *value, - unsigned int value_len, - const char *id, void *cbdata), - void *cbdata) -{ - return map_data_foreach_entry(state, FALSE, NULL, related_id, - fn, cbdata); + return map_data_foreach_entry(state, FALSE, id, fn, cbdata); } /* Iterate over all maps, calling the callback with information about the map @@ -709,7 +626,6 @@ map_data_unset_map_entry(struct plugin_state *state, } tdelete(entry, &map->key_tree, t_compare_entry_by_key); tdelete(entry, &map->id_tree, t_compare_entry_by_id); - map_id_free_id_list(entry->related_ids); free(entry->id); free(entry->key); free(entry->value); @@ -754,7 +670,6 @@ map_data_set_entry(struct plugin_state *state, const char *domain_name, const char *map_name, const char *id, - const char **related_ids, unsigned int key_len, char *key, unsigned int value_len, @@ -784,8 +699,6 @@ map_data_set_entry(struct plugin_state *state, entry->value_len = value_len; free(entry->id); entry->id = strdup(id); - map_id_free_id_list(entry->related_ids); - entry->related_ids = map_id_dup_id_list(related_ids); tsearch(entry, &map->key_tree, t_compare_entry_by_key); tsearch(entry, &map->id_tree, t_compare_entry_by_id); } else { @@ -798,7 +711,6 @@ map_data_set_entry(struct plugin_state *state, entry->value = xmemdup(value, value_len); entry->value_len = value_len; entry->id = strdup(id); - entry->related_ids = map_id_dup_id_list(related_ids); entry->next = map->entries; if (map->entries != NULL) { map->entries->prev = entry; -- cgit