summaryrefslogtreecommitdiff
path: root/src/lib/ecore_file
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-04-22 12:03:25 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-04-23 23:07:48 +0900
commite4d815dc48c660a336670ec3cc67e6becbdcacfc (patch)
tree7c9be7ba0a493b5fe40c6ea99167a0ecbe9a54f7 /src/lib/ecore_file
parent0e9cf93c3069f68d906a8b706fa1169ad1fd2073 (diff)
efreetd - reduce memory usage by using stringshare much more
lots of long paths for monitoring file paths for icons etc. are in memory for efreetd. this reduces that memory by sharing them much more. @optimization
Diffstat (limited to 'src/lib/ecore_file')
-rw-r--r--src/lib/ecore_file/ecore_file_monitor_inotify.c13
-rw-r--r--src/lib/ecore_file/ecore_file_monitor_poll.c13
-rw-r--r--src/lib/ecore_file/ecore_file_monitor_win32.c20
-rw-r--r--src/lib/ecore_file/ecore_file_private.h2
4 files changed, 23 insertions, 25 deletions
diff --git a/src/lib/ecore_file/ecore_file_monitor_inotify.c b/src/lib/ecore_file/ecore_file_monitor_inotify.c
index f86b58d631..374d709265 100644
--- a/src/lib/ecore_file/ecore_file_monitor_inotify.c
+++ b/src/lib/ecore_file/ecore_file_monitor_inotify.c
@@ -107,7 +107,8 @@ ecore_file_monitor_backend_add(const char *path,
107 void *data) 107 void *data)
108{ 108{
109 Ecore_File_Monitor *em; 109 Ecore_File_Monitor *em;
110 int len; 110 char *path2;
111 size_t len;
111 112
112 if (_inotify_fd_pid == -1) return NULL; 113 if (_inotify_fd_pid == -1) return NULL;
113 114
@@ -123,10 +124,10 @@ ecore_file_monitor_backend_add(const char *path,
123 em->func = func; 124 em->func = func;
124 em->data = data; 125 em->data = data;
125 126
126 em->path = strdup(path); 127 len = strlen(path);
127 len = strlen(em->path); 128 path2 = alloca(len + 1);
128 if (em->path[len - 1] == '/' && strcmp(em->path, "/")) 129 if (path2[len - 1] == '/' && strcmp(path2, "/")) path2[len - 1] = 0;
129 em->path[len - 1] = 0; 130 em->path = eina_stringshare_add(path2);
130 131
131 _monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em))); 132 _monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));
132 133
@@ -149,7 +150,7 @@ ecore_file_monitor_backend_del(Ecore_File_Monitor *em)
149 fd = ecore_main_fd_handler_fd_get(_fdh); 150 fd = ecore_main_fd_handler_fd_get(_fdh);
150 if (ECORE_FILE_MONITOR_INOTIFY(em)->wd) 151 if (ECORE_FILE_MONITOR_INOTIFY(em)->wd)
151 inotify_rm_watch(fd, ECORE_FILE_MONITOR_INOTIFY(em)->wd); 152 inotify_rm_watch(fd, ECORE_FILE_MONITOR_INOTIFY(em)->wd);
152 free(em->path); 153 eina_stringshare_del(em->path);
153 free(em); 154 free(em);
154} 155}
155 156
diff --git a/src/lib/ecore_file/ecore_file_monitor_poll.c b/src/lib/ecore_file/ecore_file_monitor_poll.c
index 088787e3e9..16f84194ce 100644
--- a/src/lib/ecore_file/ecore_file_monitor_poll.c
+++ b/src/lib/ecore_file/ecore_file_monitor_poll.c
@@ -68,6 +68,7 @@ ecore_file_monitor_backend_add(const char *path,
68 void *data) 68 void *data)
69{ 69{
70 Ecore_File_Monitor *em; 70 Ecore_File_Monitor *em;
71 char *path2;
71 size_t len; 72 size_t len;
72 73
73 if (!path) return NULL; 74 if (!path) return NULL;
@@ -81,14 +82,14 @@ ecore_file_monitor_backend_add(const char *path,
81 else 82 else
82 ecore_timer_interval_set(_timer, ECORE_FILE_INTERVAL_MIN); 83 ecore_timer_interval_set(_timer, ECORE_FILE_INTERVAL_MIN);
83 84
84 em->path = strdup(path);
85 len = strlen(em->path);
86 if (em->path[len - 1] == '/' && strcmp(em->path, "/"))
87 em->path[len - 1] = 0;
88
89 em->func = func; 85 em->func = func;
90 em->data = data; 86 em->data = data;
91 87
88 len = strlen(path);
89 path2 = alloca(len + 1);
90 if (path2[len - 1] == '/' && strcmp(path2, "/")) path2[len - 1] = 0;
91 em->path = eina_stringshare_add(path2);
92
92 ECORE_FILE_MONITOR_POLL(em)->mtime = ecore_file_mod_time(em->path); 93 ECORE_FILE_MONITOR_POLL(em)->mtime = ecore_file_mod_time(em->path);
93 _monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em))); 94 _monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));
94 95
@@ -160,7 +161,7 @@ ecore_file_monitor_backend_del(Ecore_File_Monitor *em)
160 if (_monitors) 161 if (_monitors)
161 _monitors = ECORE_FILE_MONITOR(eina_inlist_remove(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em))); 162 _monitors = ECORE_FILE_MONITOR(eina_inlist_remove(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));
162 163
163 free(em->path); 164 eina_stringshare_del(em->path);
164 free(em); 165 free(em);
165 166
166 if (_timer) 167 if (_timer)
diff --git a/src/lib/ecore_file/ecore_file_monitor_win32.c b/src/lib/ecore_file/ecore_file_monitor_win32.c
index f6186f6773..20f2ad02ad 100644
--- a/src/lib/ecore_file/ecore_file_monitor_win32.c
+++ b/src/lib/ecore_file/ecore_file_monitor_win32.c
@@ -243,6 +243,7 @@ ecore_file_monitor_backend_add(const char *path,
243{ 243{
244 Ecore_File_Monitor_Win32 *m; 244 Ecore_File_Monitor_Win32 *m;
245 Ecore_File_Monitor *em; 245 Ecore_File_Monitor *em;
246 char *path2;
246 size_t len; 247 size_t len;
247 248
248 if (!path || (*path == '\0')) return NULL; 249 if (!path || (*path == '\0')) return NULL;
@@ -256,22 +257,17 @@ ecore_file_monitor_backend_add(const char *path,
256 em->func = func; 257 em->func = func;
257 em->data = data; 258 em->data = data;
258 259
259 em->path = strdup(path); 260 len = strlen(path);
260 if (!em->path) 261 path2 = alloca(len + 1);
261 { 262 if (path2[len - 1] == '/' || path2[len - 1] == '\\') path2[len - 1] = 0;
262 free(em); 263 em->path = eina_stringshare_add(path2);
263 return NULL;
264 }
265 len = strlen(em->path);
266 if (em->path[len - 1] == '/' || em->path[len - 1] == '\\')
267 em->path[len - 1] = '\0';
268 264
269 m = ECORE_FILE_MONITOR_WIN32(em); 265 m = ECORE_FILE_MONITOR_WIN32(em);
270 266
271 m->file = _ecore_file_monitor_win32_data_new(em, 0); 267 m->file = _ecore_file_monitor_win32_data_new(em, 0);
272 if (!m->file) 268 if (!m->file)
273 { 269 {
274 free(em->path); 270 eina_stringshare_del(em->path);
275 free(em); 271 free(em);
276 return NULL; 272 return NULL;
277 } 273 }
@@ -280,7 +276,7 @@ ecore_file_monitor_backend_add(const char *path,
280 if (!m->dir) 276 if (!m->dir)
281 { 277 {
282 _ecore_file_monitor_win32_data_free(m->file); 278 _ecore_file_monitor_win32_data_free(m->file);
283 free(em->path); 279 eina_stringshare_del(em->path);
284 free(em); 280 free(em);
285 return NULL; 281 return NULL;
286 } 282 }
@@ -301,6 +297,6 @@ ecore_file_monitor_backend_del(Ecore_File_Monitor *em)
301 m = ECORE_FILE_MONITOR_WIN32(em); 297 m = ECORE_FILE_MONITOR_WIN32(em);
302 _ecore_file_monitor_win32_data_free(m->dir); 298 _ecore_file_monitor_win32_data_free(m->dir);
303 _ecore_file_monitor_win32_data_free(m->file); 299 _ecore_file_monitor_win32_data_free(m->file);
304 free(em->path); 300 eina_stringshare_del(em->path);
305 free(em); 301 free(em);
306} 302}
diff --git a/src/lib/ecore_file/ecore_file_private.h b/src/lib/ecore_file/ecore_file_private.h
index 82f9767153..7c33ec8f34 100644
--- a/src/lib/ecore_file/ecore_file_private.h
+++ b/src/lib/ecore_file/ecore_file_private.h
@@ -76,7 +76,7 @@ struct _Ecore_File_Monitor
76 Ecore_File_Event event, 76 Ecore_File_Event event,
77 const char *path); 77 const char *path);
78 78
79 char *path; 79 const char *path;
80 void *data; 80 void *data;
81 Ecore_File *files; 81 Ecore_File *files;
82}; 82};