[vhffs-dev] [1541] improved vhffsfssync_pathname() |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1541
Author: gradator
Date: 2010-01-20 23:12:24 +0100 (Wed, 20 Jan 2010)
Log Message:
-----------
improved vhffsfssync_pathname()
Modified Paths:
--------------
trunk/vhffs-fssync/vhffsfssync_master.c
Modified: trunk/vhffs-fssync/vhffsfssync_master.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_master.c 2010-01-19 00:41:00 UTC (rev 1540)
+++ trunk/vhffs-fssync/vhffsfssync_master.c 2010-01-20 22:12:24 UTC (rev 1541)
@@ -577,7 +577,6 @@
}
-// TODO: improve that, using *watch is probably faster
char *vhffsfssync_net_parent_mtime(char *pathname) {
char *cur;
struct stat st;
@@ -1203,21 +1202,37 @@
char *vhffsfssync_pathname(vhffsfssync_watch *watch, const char *filename) {
GString *pathname = g_string_sized_new(256);
+ char **dirnames, **curnames, **endnames;
+ uint32_t a;
- // TODO: improve that, prepend is probably slow
+ a = 16;
+ dirnames = malloc( a * sizeof(char*) );
+ curnames = dirnames;
+ endnames = dirnames+a;
+
+ if(filename) {
+ *(curnames++) = (char*)filename;
+ }
+
while(watch) {
- g_string_prepend_c(pathname, '/');
- g_string_prepend(pathname, watch->dirname);
+ *(curnames++) = watch->dirname;
watch = watch->parent;
+ if(curnames == endnames) {
+ a += 16;
+ dirnames = realloc( dirnames, a * sizeof(char*) );
+ curnames = dirnames+a-16;
+ endnames = dirnames+a;
+ }
}
- if(filename) {
- g_string_append(pathname, filename);
+ curnames--;
+ g_string_append(pathname, *(curnames--) );
+ while( curnames >= dirnames ) {
+ g_string_append_c(pathname, '/');
+ g_string_append(pathname, *(curnames--) );
}
+ free(dirnames);
-// if(watch) printf("=d> %s\n", watch->dirname);
-// if(filename) printf("=f> %s\n", filename);
-// printf("==> %s\n", pathname->str);
return g_string_free(pathname, FALSE);
}