summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-09-11 11:23:50 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-09-11 11:23:50 +0900
commit5290befb53a0ab27a18bea23bb688ecf8624b717 (patch)
tree1c84e7706045bbadb1f91a8c0f54704831c88fae
parent164299e689b6e08aa64024209710831e9bd63a29 (diff)
eo: add a small object cache to make memory recycling faster.
-rw-r--r--src/lib/eo/eo.c23
-rw-r--r--src/lib/eo/eo_private.h21
2 files changed, 42 insertions, 2 deletions
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index b1f2d15d2e..835eb86178 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -687,6 +687,8 @@ eo_class_funcs_set(Eo_Class *klass_id, const Eo_Op_Func_Description *func_descs)
687static void 687static void
688eo_class_free(_Eo_Class *klass) 688eo_class_free(_Eo_Class *klass)
689{ 689{
690 void *object;
691
690 if (klass->constructed) 692 if (klass->constructed)
691 { 693 {
692 if (klass->desc->class_destructor) 694 if (klass->desc->class_destructor)
@@ -695,6 +697,11 @@ eo_class_free(_Eo_Class *klass)
695 _dich_func_clean_all(klass); 697 _dich_func_clean_all(klass);
696 } 698 }
697 699
700 EINA_TRASH_CLEAN(&klass->trash, object)
701 free(object);
702
703 eina_lock_free(&klass->trash_lock);
704
698 free(klass); 705 free(klass);
699} 706}
700 707
@@ -886,6 +893,7 @@ eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent_id, ...)
886 893
887 klass = calloc(1, _eo_class_sz + extn_sz + mro_sz + mixins_sz); 894 klass = calloc(1, _eo_class_sz + extn_sz + mro_sz + mixins_sz);
888 EINA_MAGIC_SET(klass, EO_CLASS_EINA_MAGIC); 895 EINA_MAGIC_SET(klass, EO_CLASS_EINA_MAGIC);
896 eina_lock_new(&klass->trash_lock);
889 klass->parent = parent; 897 klass->parent = parent;
890 klass->desc = desc; 898 klass->desc = desc;
891 klass->extensions = (const _Eo_Class **) ((char *) klass + _eo_class_sz); 899 klass->extensions = (const _Eo_Class **) ((char *) klass + _eo_class_sz);
@@ -1073,6 +1081,7 @@ EAPI Eo *
1073eo_add_internal(const char *file, int line, const Eo_Class *klass_id, Eo *parent_id, ...) 1081eo_add_internal(const char *file, int line, const Eo_Class *klass_id, Eo *parent_id, ...)
1074{ 1082{
1075 Eina_Bool do_err; 1083 Eina_Bool do_err;
1084 _Eo *obj;
1076 _Eo_Class *klass = _eo_class_pointer_get(klass_id); 1085 _Eo_Class *klass = _eo_class_pointer_get(klass_id);
1077 EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL); 1086 EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL);
1078 1087
@@ -1087,7 +1096,19 @@ eo_add_internal(const char *file, int line, const Eo_Class *klass_id, Eo *parent
1087 return NULL; 1096 return NULL;
1088 } 1097 }
1089 1098
1090 _Eo *obj = calloc(1, klass->obj_size); 1099 eina_lock_take(&klass->trash_lock);
1100 obj = eina_trash_pop(&klass->trash);
1101 if (obj)
1102 {
1103 memset(obj, 0, klass->obj_size);
1104 klass->trash_count--;
1105 }
1106 else
1107 {
1108 obj = calloc(1, klass->obj_size);
1109 }
1110 eina_lock_release(&klass->trash_lock);
1111
1091 obj->refcount++; 1112 obj->refcount++;
1092 obj->klass = klass; 1113 obj->klass = klass;
1093 1114
diff --git a/src/lib/eo/eo_private.h b/src/lib/eo/eo_private.h
index b236b08f8f..591251771a 100644
--- a/src/lib/eo/eo_private.h
+++ b/src/lib/eo/eo_private.h
@@ -139,6 +139,11 @@ struct _Eo_Class
139 139
140 const _Eo_Class **mro; 140 const _Eo_Class **mro;
141 141
142 /* cached object for faster allocation */
143 Eina_Trash *trash;
144 Eina_Lock trash_lock;
145 unsigned int trash_count;
146
142 unsigned int obj_size; /**< size of an object of this class */ 147 unsigned int obj_size; /**< size of an object of this class */
143 unsigned int chain_size; 148 unsigned int chain_size;
144 unsigned int base_id; 149 unsigned int base_id;
@@ -204,6 +209,8 @@ _eo_del_internal(const char *file, int line, _Eo *obj)
204static inline void 209static inline void
205_eo_free(_Eo *obj) 210_eo_free(_Eo *obj)
206{ 211{
212 _Eo_Class *klass = (_Eo_Class*) obj->klass;
213
207#ifdef EO_DEBUG 214#ifdef EO_DEBUG
208 if (obj->datarefcount) 215 if (obj->datarefcount)
209 { 216 {
@@ -211,7 +218,19 @@ _eo_free(_Eo *obj)
211 } 218 }
212#endif 219#endif
213 _eo_id_release(obj->obj_id); 220 _eo_id_release(obj->obj_id);
214 free(obj); 221
222 eina_lock_take(&klass->trash_lock);
223 if (klass->trash_count <= 8)
224 {
225 eina_trash_push(&klass->trash, obj);
226 klass->trash_count++;
227 eina_lock_release(&klass->trash_lock);
228 }
229 else
230 {
231 eina_lock_release(&klass->trash_lock);
232 free(obj);
233 }
215} 234}
216 235
217static inline _Eo * 236static inline _Eo *