diff options
author | Peter J. R. Moulder <pjmoulder@src.gnome.org> | 2008-03-30 13:02:34 +0000 |
---|---|---|
committer | Peter J. R. Moulder <pjmoulder@src.gnome.org> | 2008-03-30 13:02:34 +0000 |
commit | aaebd96e3fe79421f8c819443b09fb16e473c70a (patch) | |
tree | 2c774a47660e9e137f6b989a7f35b4d72f5ae5a6 | |
parent | 53364d93a2752474b205cd718d160d58d5fe773b (diff) | |
download | libcroco-aaebd96e3fe79421f8c819443b09fb16e473c70a.tar.gz |
minor: (cr_declaration_destroy): Simplify implementation (and assert that next/prev elements point to each other).
svn path=/trunk/; revision=318
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | src/cr-declaration.c | 47 |
2 files changed, 13 insertions, 36 deletions
@@ -13,6 +13,8 @@ existing code will break from this. * src/cr-declaration.c: (cr_declaration_new): Doc. + * (cr_declaration_destroy): Simplify implementation (and assert that + next/prev elements point to each other before following the links). 2007-01-10 Bruno Haible <bruno@clisp.org> diff --git a/src/cr-declaration.c b/src/cr-declaration.c index 13ac82a..8079aa0 100644 --- a/src/cr-declaration.c +++ b/src/cr-declaration.c @@ -773,22 +773,19 @@ cr_declaration_destroy (CRDeclaration * a_this) g_return_if_fail (a_this); /* - *Go get the tail of the list. - *Meanwhile, free each property/value pair contained in the list. + * Go to the last element of the list. */ - for (cur = a_this; cur && cur->next; cur = cur->next) { - if (cur->property) { - cr_string_destroy (cur->property); - cur->property = NULL; - } + for (cur = a_this; cur->next; cur = cur->next) + g_assert (cur->next->prev == cur); - if (cur->value) { - cr_term_destroy (cur->value); - cur->value = NULL; - } - } + /* + * Walk backward the list and free each "next" element. + * Meanwhile, free each property/value pair contained in the list. + */ + for (; cur; cur = cur->prev) { + g_free (cur->next); + cur->next = NULL; - if (cur) { if (cur->property) { cr_string_destroy (cur->property); cur->property = NULL; @@ -800,27 +797,5 @@ cr_declaration_destroy (CRDeclaration * a_this) } } - /*in case the list contains only one element */ - if (cur && !cur->prev) { - g_free (cur); - return; - } - - /*walk backward the list and free each "next" element */ - for (cur = cur->prev; cur && cur->prev; cur = cur->prev) { - if (cur->next) { - g_free (cur->next); - cur->next = NULL; - } - } - - if (!cur) - return; - - if (cur->next) { - g_free (cur->next); - cur->next = NULL; - } - - g_free (cur); + g_free (a_this); } |