[geany/geany] 8aa4f1: Optimize notebook page -> document lookup and remove dead code

Colomban Wendling git-noreply at xxxxx
Sat Feb 21 17:56:51 UTC 2015


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sat, 21 Feb 2015 17:56:51 UTC
Commit:      8aa4f11cad2cf8404bc58f93464fdcd2140a2f69
             https://github.com/geany/geany/commit/8aa4f11cad2cf8404bc58f93464fdcd2140a2f69

Log Message:
-----------
Optimize notebook page -> document lookup and remove dead code

This actually fixes a theoretical bug introduced when notebook pages
stopped being ScintillaWidgets, but this bug had no effect because it
was in a dead code path -- because no, `page_num` never is -1 nor
`page` NULL.


Modified Paths:
--------------
    src/callbacks.c
    src/document.c
    src/document.h

Modified: src/callbacks.c
5 lines changed, 1 insertions(+), 4 deletions(-)
===================================================================
@@ -540,10 +540,7 @@ G_MODULE_EXPORT void on_notebook1_switch_page_after(GtkNotebook *notebook, gpoin
 	if (G_UNLIKELY(main_status.opening_session_files || main_status.closing_all))
 		return;
 
-	if (page_num == (guint) -1 && page != NULL)
-		doc = document_find_by_sci(SCINTILLA(page));
-	else
-		doc = document_get_from_page(page_num);
+	doc = document_get_from_notebook_child(page);
 
 	if (doc != NULL)
 	{


Modified: src/document.c
21 lines changed, 15 insertions(+), 6 deletions(-)
===================================================================
@@ -338,6 +338,20 @@ static ScintillaObject *locate_sci_in_container(GtkWidget *container)
 }
 
 
+/* Finds the document for the given notebook page widget */
+GeanyDocument *document_get_from_notebook_child(GtkWidget *page)
+{
+	ScintillaObject *sci;
+
+	g_return_val_if_fail(GTK_IS_BOX(page), NULL);
+
+	sci = locate_sci_in_container(page);
+	g_return_val_if_fail(IS_SCINTILLA(sci), NULL);
+
+	return document_find_by_sci(sci);
+}
+
+
 /**
  *  Finds the document for the given notebook page @a page_num.
  *
@@ -348,18 +362,13 @@ static ScintillaObject *locate_sci_in_container(GtkWidget *container)
 GeanyDocument *document_get_from_page(guint page_num)
 {
 	GtkWidget *parent;
-	ScintillaObject *sci;
 
 	if (page_num >= documents_array->len)
 		return NULL;
 
 	parent = gtk_notebook_get_nth_page(GTK_NOTEBOOK(main_widgets.notebook), page_num);
-	g_return_val_if_fail(GTK_IS_BOX(parent), NULL);
 
-	sci = locate_sci_in_container(parent);
-	g_return_val_if_fail(IS_SCINTILLA(sci), NULL);
-
-	return document_find_by_sci(sci);
+	return document_get_from_notebook_child(parent);
 }
 
 


Modified: src/document.h
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -172,6 +172,8 @@ GeanyDocument* document_new_file(const gchar *filename, GeanyFiletype *ft, const
 
 GeanyDocument *document_get_current(void);
 
+GeanyDocument *document_get_from_notebook_child(GtkWidget *page);
+
 GeanyDocument* document_get_from_page(guint page_num);
 
 GeanyDocument* document_find_by_filename(const gchar *utf8_filename);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list