[waffle] [PATCH 08/11] core Add func wcore_attrib_list_pop()
Chad Versace
chad.versace at linux.intel.com
Tue Dec 16 00:18:32 PST 2014
This is useful for removing attributes as they are parsed.
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
src/waffle/core/wcore_attrib_list.c | 39 +++++++++++++++++++++++++++++++++++++
src/waffle/core/wcore_attrib_list.h | 6 ++++++
2 files changed, 45 insertions(+)
diff --git a/src/waffle/core/wcore_attrib_list.c b/src/waffle/core/wcore_attrib_list.c
index 94013b9..4e912fd 100644
--- a/src/waffle/core/wcore_attrib_list.c
+++ b/src/waffle/core/wcore_attrib_list.c
@@ -99,6 +99,45 @@ wcore_attrib_list_get_with_default(
}
bool
+wcore_attrib_list_pop(
+ intptr_t attrib_list[],
+ intptr_t key,
+ intptr_t *value)
+{
+ // Address of key in attrib_list.
+ intptr_t *key_addr = NULL;
+
+ // Address of one past the last element in attrib_list.
+ intptr_t *end = NULL;
+
+ if (attrib_list == NULL) {
+ return false;
+ }
+
+ for (intptr_t *i = attrib_list; *i; i += 2) {
+ if (i[0] == key) {
+ key_addr = i;
+ *value = i[1];
+ break;
+ }
+ }
+
+ if (!key_addr) {
+ return false;
+ }
+
+ end = key_addr + 2;
+ while (*end) {
+ end += 2;
+ }
+ ++end;
+
+ memmove(key_addr, key_addr + 2,
+ sizeof(intptr_t) * (end - (key_addr + 2)));
+ return true;
+}
+
+bool
wcore_attrib_list_update(
intptr_t *attrib_list,
intptr_t key,
diff --git a/src/waffle/core/wcore_attrib_list.h b/src/waffle/core/wcore_attrib_list.h
index bd1179d..e5240c3 100644
--- a/src/waffle/core/wcore_attrib_list.h
+++ b/src/waffle/core/wcore_attrib_list.h
@@ -49,6 +49,12 @@ wcore_attrib_list_get_with_default(
intptr_t default_value);
bool
+wcore_attrib_list_pop(
+ intptr_t attrib_list[],
+ intptr_t key,
+ intptr_t *value);
+
+bool
wcore_attrib_list_update(
intptr_t *attrib_list,
intptr_t key,
--
2.2.0
More information about the waffle
mailing list