diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-30 23:31:39 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-30 23:31:39 +0000 |
commit | c22dfdda13a5ec5c9698c3205ca0bc32f14884ce (patch) | |
tree | 3b7ab81ffb6860867732680ebd30ac8c9f610207 | |
parent | bc1b28bd52155c8b0175f28bfcc63ae3c91be3e3 (diff) | |
download | gnunet-gtk-c22dfdda13a5ec5c9698c3205ca0bc32f14884ce.tar.gz gnunet-gtk-c22dfdda13a5ec5c9698c3205ca0bc32f14884ce.zip |
-eliminating tree traversal travesty
-rw-r--r-- | src/fs/gnunet-fs-gtk-main_window_file_publish.c | 61 |
1 files changed, 13 insertions, 48 deletions
diff --git a/src/fs/gnunet-fs-gtk-main_window_file_publish.c b/src/fs/gnunet-fs-gtk-main_window_file_publish.c index d44d2c63..813aa21b 100644 --- a/src/fs/gnunet-fs-gtk-main_window_file_publish.c +++ b/src/fs/gnunet-fs-gtk-main_window_file_publish.c | |||
@@ -867,67 +867,31 @@ add_item (struct AddDirClientContext *adcc, GtkTreeStore *ts, | |||
867 | } | 867 | } |
868 | 868 | ||
869 | 869 | ||
870 | /* Used to avoid recursion */ | ||
871 | // FIXME: we should probably use recursion instead ;-). | ||
872 | struct AddShareItemsStack | ||
873 | { | ||
874 | struct AddShareItemsStack *parent; | ||
875 | GtkTreeIter last_added; | ||
876 | }; | ||
877 | |||
878 | |||
879 | /** | 870 | /** |
880 | * Traverse the share tree and add it to the tree store | 871 | * Traverse the share tree and add it to the tree store |
881 | * | 872 | * |
882 | */ | 873 | */ |
883 | static void | 874 | static void |
884 | add_share_items_to_treestore (struct AddDirClientContext *adcc, | 875 | add_share_items_to_treestore (struct AddDirClientContext *adcc, |
885 | struct GNUNET_FS_ShareTreeItem *toplevel) | 876 | struct GNUNET_FS_ShareTreeItem *toplevel, |
877 | GtkTreeIter *parent_iter) | ||
886 | { | 878 | { |
887 | struct MainPublishingDialogContext *ctx = adcc->ctx; | 879 | struct MainPublishingDialogContext *ctx = adcc->ctx; |
888 | GtkTreeStore *ts = GTK_TREE_STORE (ctx->file_info_treemodel); | 880 | GtkTreeStore *ts = GTK_TREE_STORE (ctx->file_info_treemodel); |
889 | GtkTreeIter *parent_iter; | ||
890 | GtkTreeIter *sibling_iter; | 881 | GtkTreeIter *sibling_iter; |
891 | struct GNUNET_FS_ShareTreeItem *item, *next; | 882 | GtkTreeIter last_added; |
892 | struct AddShareItemsStack *stack; | 883 | struct GNUNET_FS_ShareTreeItem *item; |
893 | 884 | ||
894 | stack = GNUNET_malloc (sizeof (struct AddShareItemsStack)); | ||
895 | parent_iter = NULL; | ||
896 | sibling_iter = NULL; | 885 | sibling_iter = NULL; |
897 | for (item = toplevel; item != NULL; item = next) | 886 | for (item = toplevel; item != NULL; item = item->next) |
898 | { | 887 | { |
899 | add_item (adcc, ts, item, parent_iter, sibling_iter, &stack->last_added); | 888 | add_item (adcc, ts, item, parent_iter, sibling_iter, &last_added); |
900 | sibling_iter = &stack->last_added; | 889 | sibling_iter = &last_added; |
901 | if (item->is_directory) | 890 | if (item->is_directory) |
902 | { | 891 | add_share_items_to_treestore (adcc, |
903 | if (item->children_head != NULL) | 892 | item, |
904 | { | 893 | sibling_iter); |
905 | struct AddShareItemsStack *child = GNUNET_malloc (sizeof (struct AddShareItemsStack)); | ||
906 | child->parent = stack; | ||
907 | sibling_iter = NULL; | ||
908 | parent_iter = &stack->last_added; | ||
909 | stack = child; | ||
910 | next = item->children_head; | ||
911 | continue; | ||
912 | } | ||
913 | } | ||
914 | while ((next = item->next) == NULL) | ||
915 | { | ||
916 | if (item->parent != NULL) | ||
917 | { | ||
918 | next = item->parent; | ||
919 | struct AddShareItemsStack *child; | ||
920 | sibling_iter = &stack->parent->last_added; | ||
921 | parent_iter = stack->parent->parent != NULL ? &stack->parent->parent->last_added : NULL; | ||
922 | child = stack; | ||
923 | stack = stack->parent; | ||
924 | item = next; | ||
925 | } | ||
926 | else | ||
927 | break; | ||
928 | } | ||
929 | } | 894 | } |
930 | GNUNET_free (stack); | ||
931 | } | 895 | } |
932 | 896 | ||
933 | 897 | ||
@@ -1019,7 +983,8 @@ directory_scan_cb (void *cls, | |||
1019 | adcc->ds = NULL; | 983 | adcc->ds = NULL; |
1020 | GNUNET_FS_share_tree_trim (adcc->directory_scan_result); | 984 | GNUNET_FS_share_tree_trim (adcc->directory_scan_result); |
1021 | add_share_items_to_treestore (adcc, | 985 | add_share_items_to_treestore (adcc, |
1022 | adcc->directory_scan_result); | 986 | adcc->directory_scan_result, |
987 | NULL); | ||
1023 | GNUNET_FS_share_tree_free (adcc->directory_scan_result); | 988 | GNUNET_FS_share_tree_free (adcc->directory_scan_result); |
1024 | adcc->directory_scan_result = NULL; | 989 | adcc->directory_scan_result = NULL; |
1025 | update_selectivity (adcc->ctx); | 990 | update_selectivity (adcc->ctx); |