summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2012-09-11 03:37:10 +0000
committerCedric BAIL <cedric.bail@free.fr>2012-09-11 03:37:10 +0000
commit704cfbe1b59c58f46eb4d797b39a3481301f4704 (patch)
tree43c9a47b36ad5063c6d14306291b788956a435c3
parenta52cb9e0f541cc4070c2b3f7465b1420d62a6778 (diff)
eina: be green and recycle memory needed by Eina_Rbtree iterator.
SVN revision: 76425
-rw-r--r--legacy/eina/ChangeLog4
-rw-r--r--legacy/eina/NEWS8
-rw-r--r--legacy/eina/src/lib/eina_rbtree.c35
3 files changed, 35 insertions, 12 deletions
diff --git a/legacy/eina/ChangeLog b/legacy/eina/ChangeLog
index b27fa052c2..403c9d7df7 100644
--- a/legacy/eina/ChangeLog
+++ b/legacy/eina/ChangeLog
@@ -337,3 +337,7 @@
337 337
338 * Fix EINA_INLIST_FOREACH_SAFE macro to work when inlist is not the 338 * Fix EINA_INLIST_FOREACH_SAFE macro to work when inlist is not the
339 first item in the struct. 339 first item in the struct.
340
3412012-09-11 Cedric Bail
342
343 * Speedup Eina Rbtree Iterator by recycling memory instead of massively calling malloc/free.
diff --git a/legacy/eina/NEWS b/legacy/eina/NEWS
index 2c364ce2d6..c6b08c9ff7 100644
--- a/legacy/eina/NEWS
+++ b/legacy/eina/NEWS
@@ -1,3 +1,11 @@
1Eina 1.8.0
2
3Changes since Eina 1.7.0:
4-------------------------
5
6Improvements:
7 * Speedup Eina Rbtree Iterator by recycling memory instead of massively calling malloc/free.
8
1Eina 1.7.0 9Eina 1.7.0
2 10
3Changes since Eina 1.2.0: 11Changes since Eina 1.2.0:
diff --git a/legacy/eina/src/lib/eina_rbtree.c b/legacy/eina/src/lib/eina_rbtree.c
index a9d777a230..394007f964 100644
--- a/legacy/eina/src/lib/eina_rbtree.c
+++ b/legacy/eina/src/lib/eina_rbtree.c
@@ -29,6 +29,7 @@
29#include "eina_config.h" 29#include "eina_config.h"
30#include "eina_private.h" 30#include "eina_private.h"
31#include "eina_array.h" 31#include "eina_array.h"
32#include "eina_trash.h"
32 33
33/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ 34/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
34#include "eina_safety_checks.h" 35#include "eina_safety_checks.h"
@@ -50,6 +51,7 @@ struct _Eina_Iterator_Rbtree
50 Eina_Iterator iterator; 51 Eina_Iterator iterator;
51 52
52 Eina_Array *stack; 53 Eina_Array *stack;
54 Eina_Trash *trash;
53 55
54 unsigned char mask; 56 unsigned char mask;
55}; 57};
@@ -63,16 +65,20 @@ struct _Eina_Iterator_Rbtree_List
63}; 65};
64 66
65static Eina_Iterator_Rbtree_List * 67static Eina_Iterator_Rbtree_List *
66_eina_rbtree_iterator_list_new(const Eina_Rbtree *tree) 68_eina_rbtree_iterator_list_new(Eina_Iterator_Rbtree *it, const Eina_Rbtree *tree)
67{ 69{
68 Eina_Iterator_Rbtree_List *new; 70 Eina_Iterator_Rbtree_List *new;
69 71
70 eina_error_set(0); 72 eina_error_set(0);
71 new = malloc(sizeof (Eina_Iterator_Rbtree_List)); 73 new = eina_trash_pop(&it->trash);
72 if (!new) 74 if (!new)
73 { 75 {
74 eina_error_set(EINA_ERROR_OUT_OF_MEMORY); 76 new = malloc(sizeof (Eina_Iterator_Rbtree_List));
75 return NULL; 77 if (!new)
78 {
79 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
80 return NULL;
81 }
76 } 82 }
77 83
78 new->tree = (Eina_Rbtree *)tree; 84 new->tree = (Eina_Rbtree *)tree;
@@ -97,12 +103,15 @@ _eina_rbtree_iterator_free(Eina_Iterator_Rbtree *it)
97 Eina_Iterator_Rbtree_List *item; 103 Eina_Iterator_Rbtree_List *item;
98 Eina_Array_Iterator et; 104 Eina_Array_Iterator et;
99 unsigned int i; 105 unsigned int i;
106 void *last;
100 107
101 EINA_ARRAY_ITER_NEXT(it->stack, i, item, et) 108 EINA_ARRAY_ITER_NEXT(it->stack, i, item, et)
102 free(item); 109 free(item);
103 110
104 eina_array_free(it->stack); 111 eina_array_free(it->stack);
105 free(it); 112 while ((last = eina_trash_pop(&it->trash)))
113 free(last);
114 free(it);
106} 115}
107 116
108static Eina_Bool 117static Eina_Bool
@@ -128,7 +137,7 @@ _eina_rbtree_iterator_next(Eina_Iterator_Rbtree *it, void **data)
128 if ((it->mask & EINA_RBTREE_ITERATOR_POSTFIX_MASK) == 137 if ((it->mask & EINA_RBTREE_ITERATOR_POSTFIX_MASK) ==
129 EINA_RBTREE_ITERATOR_POSTFIX_MASK) 138 EINA_RBTREE_ITERATOR_POSTFIX_MASK)
130 { 139 {
131 free(last); 140 eina_trash_push(&it->trash, last);
132 141
133 if (eina_array_count(it->stack) > 0) 142 if (eina_array_count(it->stack) > 0)
134 { 143 {
@@ -143,7 +152,7 @@ _eina_rbtree_iterator_next(Eina_Iterator_Rbtree *it, void **data)
143 goto onfix; 152 goto onfix;
144 } 153 }
145 154
146 free(last); 155 eina_trash_push(&it->trash, last);
147 156
148 last = eina_array_pop(it->stack); 157 last = eina_array_pop(it->stack);
149 if (!last) 158 if (!last)
@@ -162,11 +171,11 @@ _eina_rbtree_iterator_next(Eina_Iterator_Rbtree *it, void **data)
162 goto onfix; 171 goto onfix;
163 } 172 }
164 173
165 new = _eina_rbtree_iterator_list_new(last->tree->son[last->dir]); 174 new = _eina_rbtree_iterator_list_new(it, last->tree->son[last->dir]);
166 if (!new) 175 if (!new)
167 return EINA_FALSE; 176 return EINA_FALSE;
168 177
169 eina_array_push(it->stack, new); 178 eina_array_push(it->stack, new);
170 179
171 if (last->dir == EINA_RBTREE_RIGHT) 180 if (last->dir == EINA_RBTREE_RIGHT)
172 if ((it->mask & EINA_RBTREE_ITERATOR_PREFIX_MASK) == 181 if ((it->mask & EINA_RBTREE_ITERATOR_PREFIX_MASK) ==
@@ -194,11 +203,13 @@ _eina_rbtree_iterator_build(const Eina_Rbtree *root, unsigned char mask)
194 return NULL; 203 return NULL;
195 } 204 }
196 205
206 eina_trash_init(&it->trash);
207
197 it->stack = eina_array_new(8); 208 it->stack = eina_array_new(8);
198 if (!it->stack) 209 if (!it->stack)
199 goto on_error2; 210 goto on_error2;
200 211
201 first = _eina_rbtree_iterator_list_new(root); 212 first = _eina_rbtree_iterator_list_new(it, root);
202 if (!first) 213 if (!first)
203 goto on_error; 214 goto on_error;
204 215