devhelp r1133 - in trunk: . src



Author: rhult
Date: Sat Oct  4 16:29:48 2008
New Revision: 1133
URL: http://svn.gnome.org/viewvc/devhelp?rev=1133&view=rev

Log:
2008-10-04  Richard Hult  <richard imendio com>

	* src/dh-link.[ch]: Only keep the "leaf" part of the URI in each
	link, and the base part in the book. Construct the full URI on
	demand. This saves lots and lots of allocations and memory.

	* src/dh-book-tree.c: (book_tree_find_uri_foreach):
	* src/dh-parser.c: (parser_start_node_book),
	(parser_start_node_chapter), (parser_start_node_keyword):
	* src/dh-window.c: (window_tree_link_selected_cb),
	(window_search_link_selected_cb): Adapt to the
	above (dh_link_get_uri() now returns allocated memory).


Modified:
   trunk/ChangeLog
   trunk/src/dh-book-tree.c
   trunk/src/dh-link.c
   trunk/src/dh-link.h
   trunk/src/dh-parser.c
   trunk/src/dh-window.c

Modified: trunk/src/dh-book-tree.c
==============================================================================
--- trunk/src/dh-book-tree.c	(original)
+++ trunk/src/dh-book-tree.c	Sat Oct  4 16:29:48 2008
@@ -246,6 +246,7 @@
 {
 	DhLink      *link;
 	const gchar *uri;
+        gchar       *link_uri;
 
 	gtk_tree_model_get (model, iter,
 			    COL_LINK, &link,
@@ -258,11 +259,13 @@
 		uri = data->uri;
 	}
 
-	if (g_str_has_prefix (uri, dh_link_get_uri (link))) {
+        link_uri = dh_link_get_uri (link);
+	if (g_str_has_prefix (uri, link_uri)) {
 		data->found = TRUE;
 		data->iter = *iter;
 		data->path = gtk_tree_path_copy (path);
 	}
+        g_free (link_uri);
 
 	return data->found;
 }

Modified: trunk/src/dh-link.c
==============================================================================
--- trunk/src/dh-link.c	(original)
+++ trunk/src/dh-link.c	Sat Oct  4 16:29:48 2008
@@ -26,7 +26,11 @@
 #include "dh-link.h"
 
 struct _DhLink {
+        /* FIXME: Those two could exist only for book to save some
+         * memory.
+         */
         gchar       *id;
+        gchar       *base;
 
         gchar       *name;
         gchar       *uri;
@@ -57,6 +61,7 @@
 static void
 link_free (DhLink *link)
 {
+	g_free (link->base);
 	g_free (link->id);
 	g_free (link->name);
 	g_free (link->uri);
@@ -73,6 +78,7 @@
 
 DhLink *
 dh_link_new (DhLinkType   type,
+             const gchar *base,
 	     const gchar *id,
 	     const gchar *name,
 	     DhLink      *book,
@@ -84,14 +90,24 @@
 	g_return_val_if_fail (name != NULL, NULL);
 	g_return_val_if_fail (uri != NULL, NULL);
 
+        if (type == DH_LINK_TYPE_BOOK) {
+                g_return_val_if_fail (base != NULL, NULL);
+                g_return_val_if_fail (id != NULL, NULL);
+        }
+        if (type != DH_LINK_TYPE_BOOK && type != DH_LINK_TYPE_PAGE) {
+                g_return_val_if_fail (book != NULL, NULL);
+                g_return_val_if_fail (page != NULL, NULL);
+        }
+        
 	link = g_slice_new0 (DhLink);
 
 	link->ref_count = 1;
 	link->type = type;
 
+	link->base = g_strdup (base);
 	link->id = g_strdup (id);
 	link->name = g_strdup (name);
-	link->uri  = g_strdup (uri);
+	link->uri = g_strdup (uri);
 
 	if (book) {
                 link->book = dh_link_ref (book);
@@ -200,10 +216,14 @@
         return "";
 }
 
-const gchar *
+gchar *
 dh_link_get_uri (DhLink *link)
 {
-        return link->uri;
+        if (link->type == DH_LINK_TYPE_BOOK) {
+                return g_strconcat (link->base, "/", link->uri, NULL);
+        }
+
+        return g_strconcat (link->book->base, "/", link->uri, NULL);
 }
 
 DhLinkType

Modified: trunk/src/dh-link.h
==============================================================================
--- trunk/src/dh-link.h	(original)
+++ trunk/src/dh-link.h	Sat Oct  4 16:29:48 2008
@@ -47,6 +47,7 @@
 
 GType        dh_link_get_type           (void);
 DhLink *     dh_link_new                (DhLinkType     type,
+                                         const gchar   *base,
                                          const gchar   *id,
 					 const gchar   *name,
                                          DhLink        *book,
@@ -61,7 +62,7 @@
 const gchar *dh_link_get_book_name      (DhLink        *link);
 const gchar *dh_link_get_page_name      (DhLink        *link);
 const gchar *dh_link_get_book_id        (DhLink        *link);
-const gchar *dh_link_get_uri            (DhLink        *link);
+gchar       *dh_link_get_uri            (DhLink        *link);
 DhLinkFlags  dh_link_get_flags          (DhLink        *link);
 void         dh_link_set_flags          (DhLink        *link,
 					 DhLinkFlags    flags);

Modified: trunk/src/dh-parser.c
==============================================================================
--- trunk/src/dh-parser.c	(original)
+++ trunk/src/dh-parser.c	Sat Oct  4 16:29:48 2008
@@ -56,20 +56,6 @@
 	gint                 version;
 } DhParser;
 
-static gchar *
-extract_page_name (const gchar *uri)
-{
-	gchar  *page = NULL;
-	gchar **split;
-
-	if ((split = g_strsplit (uri, ".", 2)) != NULL) {
-		page = split[0];
-                split[0] = NULL;
-		g_strfreev (split);
-	}
-	return page;
-}
-
 static void
 parser_start_node_book (DhParser             *parser,
                         GMarkupParseContext  *context,
@@ -81,10 +67,9 @@
         gint         i;
         gint         line, col;
         const gchar *title = NULL;
-        const gchar *base  = NULL;
-        const gchar *name  = NULL;
-        const gchar *uri  = NULL;
-	gchar       *full_uri;
+        const gchar *base = NULL;
+        const gchar *name = NULL;
+        const gchar *uri = NULL;
 	DhLink      *link;
 
         if (g_ascii_strcasecmp (node_name, "book") != 0) {
@@ -146,14 +131,13 @@
                 parser->base = g_path_get_dirname (parser->path);
         }
 
-        full_uri = g_strconcat (parser->base, "/", uri, NULL);
         link = dh_link_new (DH_LINK_TYPE_BOOK,
+                            parser->base,
                             name,
                             title,
                             NULL,
                             NULL,
-                            full_uri);
-        g_free (full_uri);
+                            uri);
 
         *parser->keywords = g_list_prepend (*parser->keywords, link);
 
@@ -174,8 +158,6 @@
         gint         line, col;
         const gchar *name = NULL;
         const gchar *uri = NULL;
-	gchar       *full_uri;
-	gchar       *page;
 	DhLink      *link;
         GNode       *node;
 
@@ -209,17 +191,13 @@
                 return;
         }
 
-        full_uri = g_strconcat (parser->base, "/", uri, NULL);
-        page = extract_page_name (uri);
         link = dh_link_new (DH_LINK_TYPE_PAGE,
                             NULL,
+                            NULL,
                             name, 
                             parser->book_node->data,
                             NULL,
-                            full_uri);
-
-        g_free (full_uri);
-        g_free (page);
+                            uri);
 
         *parser->keywords = g_list_prepend (*parser->keywords, link);
 
@@ -242,7 +220,6 @@
         const gchar *uri = NULL;
         const gchar *type = NULL;
         const gchar *deprecated = NULL;
-	gchar       *full_uri;
         DhLinkType   link_type;
 	DhLink      *link;
         gchar       *tmp;
@@ -307,8 +284,6 @@
                 return;
         }
 
-        full_uri = g_strconcat (parser->base, "/", uri, NULL);
-
         if (parser->version == 2) {
                 if (strcmp (type, "function") == 0) {
                         link_type = DH_LINK_TYPE_FUNCTION;
@@ -360,14 +335,14 @@
         }
 
         link = dh_link_new (link_type,
-                            NULL, // koko id
+                            NULL,
+                            NULL,
                             name, 
                             parser->book_node->data,
                             parser->parent->data,
-                            full_uri);
+                            uri);
 
         g_free (tmp);
-        g_free (full_uri);
 
         if (deprecated) {
                 dh_link_set_flags (

Modified: trunk/src/dh-window.c
==============================================================================
--- trunk/src/dh-window.c	(original)
+++ trunk/src/dh-window.c	Sat Oct  4 16:29:48 2008
@@ -915,26 +915,29 @@
                               DhWindow *window)
 {
         DhWindowPriv  *priv;
-        WebKitWebView *web_view;
+        WebKitWebView *view;
+        gchar         *uri;
 
         priv = window->priv;
 
-        web_view = window_get_active_web_view (window);
+        view = window_get_active_web_view (window);
 
-        /* Block so we don't try to sync the tree when we have already clicked
-         * in it.
+        /* Block so we don't try to sync the tree when we have already
+         * clicked in it.
          */
-        g_signal_handlers_block_by_func (web_view,
+        g_signal_handlers_block_by_func (view,
                                          window_web_view_open_uri_cb,
                                          window);
 
-        webkit_web_view_open (web_view, dh_link_get_uri (link));
+        uri = dh_link_get_uri (link);
+        webkit_web_view_open (view, uri);
+        g_free (uri);
 
-        g_signal_handlers_unblock_by_func (web_view,
+        g_signal_handlers_unblock_by_func (view,
                                            window_web_view_open_uri_cb,
                                            window);
 
-        window_check_history (window, web_view);
+        window_check_history (window, view);
 }
 
 static void
@@ -943,15 +946,18 @@
                                 DhWindow *window)
 {
         DhWindowPriv  *priv;
-        WebKitWebView *web_view;
+        WebKitWebView *view;
+        gchar         *uri;
 
         priv = window->priv;
 
-        web_view = window_get_active_web_view (window);
+        view = window_get_active_web_view (window);
 
-        webkit_web_view_open (web_view, dh_link_get_uri (link));
+        uri = dh_link_get_uri (link);
+        webkit_web_view_open (view, uri);
+        g_free (uri);
 
-        window_check_history (window, web_view);
+        window_check_history (window, view);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]