[svn:parrot] r47331 - branches/gc_massacre/src/gc

bacek at svn.parrot.org bacek at svn.parrot.org
Thu Jun 3 10:31:39 UTC 2010


Author: bacek
Date: Thu Jun  3 10:31:38 2010
New Revision: 47331
URL: https://trac.parrot.org/parrot/changeset/47331

Log:
Poor-man templates: implement macros for manipulating lists

Modified:
   branches/gc_massacre/src/gc/list.c
   branches/gc_massacre/src/gc/list.h

Modified: branches/gc_massacre/src/gc/list.c
==============================================================================
--- branches/gc_massacre/src/gc/list.c	Thu Jun  3 10:31:18 2010	(r47330)
+++ branches/gc_massacre/src/gc/list.c	Thu Jun  3 10:31:38 2010	(r47331)
@@ -136,7 +136,6 @@
     if (next)
         next->prev = prev;
 
-    item->prev = item->next = NULL;
     list->count--;
     return item;
 }
@@ -157,9 +156,10 @@
 {
     ASSERT_ARGS(Parrot_gc_list_pop)
 
-    if (!list->first)
-        return NULL;
-    return Parrot_gc_list_remove(interp, list, list->first);
+    List_Item_Header *ret = list->first;
+    if (ret)
+        LIST_REMOVE(list, ret);
+    return ret;
 }
 
 /*

Modified: branches/gc_massacre/src/gc/list.h
==============================================================================
--- branches/gc_massacre/src/gc/list.h	Thu Jun  3 10:31:18 2010	(r47330)
+++ branches/gc_massacre/src/gc/list.h	Thu Jun  3 10:31:38 2010	(r47331)
@@ -41,6 +41,56 @@
 #define LLH2Obj_typed(p, type) ((type*)((char*)(p) + sizeof (List_Item_Header)))
 #define LLH2Obj(p) LLH2Obj_typed(p, void)
 
+#ifdef NDEBUG
+#  define SET_LIST_OWNER(l, i)
+#else
+#  define SET_LIST_OWNER(l, i) (i)->owner = (l);
+#endif
+
+#define LIST_APPEND(l, i)                   \
+do {                                        \
+    List_Item_Header *_item = (i);          \
+    Linked_List      *_list = (l);          \
+    (_item)->prev = (_item)->next = NULL;   \
+                                            \
+    if (_list->last) {                      \
+        _item->prev = _list->last;          \
+        _list->last->next = _item;          \
+    }                                       \
+                                            \
+    _list->last = _item;                    \
+                                            \
+    if (!_list->first)                      \
+        _list->first = _item;               \
+                                            \
+    SET_LIST_OWNER(_list, _item)            \
+    _list->count++;                         \
+} while(0);
+
+#define LIST_REMOVE(l, i)                   \
+do {                                        \
+    List_Item_Header *_item = (i);          \
+    Linked_List      *_list = (l);          \
+    List_Item_Header *next = _item->next;   \
+    List_Item_Header *prev = _item->prev;   \
+                                            \
+    PARROT_ASSERT(_list == _item->owner);   \
+                                            \
+    /* First _item */                       \
+    if (_list->first == _item)              \
+        _list->first = next;                \
+                                            \
+    if (_list->last == _item)               \
+        _list->last = prev;                 \
+                                            \
+    if (prev)                               \
+        prev->next = next;                  \
+    if (next)                               \
+        next->prev = prev;                  \
+                                            \
+    _list->count--;                         \
+} while(0)
+
 
 /* HEADERIZER BEGIN: src/gc/list.c */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */


More information about the parrot-commits mailing list