SF.net SVN: geany:[3571] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Tue Feb 10 21:11:26 UTC 2009


Revision: 3571
          http://geany.svn.sourceforge.net/geany/?rev=3571&view=rev
Author:   eht16
Date:     2009-02-10 21:11:25 +0000 (Tue, 10 Feb 2009)

Log Message:
-----------
Small optimisations by moving out function calls of loop break conditions (patch by Frank, thanks).

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/plugins/export.c
    trunk/plugins/filebrowser.c
    trunk/plugins/htmlchars.c
    trunk/plugins/vcdiff.c
    trunk/src/document.c
    trunk/src/search.c
    trunk/src/templates.c
    trunk/src/tools.c
    trunk/src/treeviews.c
    trunk/src/utils.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-02-10 21:10:50 UTC (rev 3570)
+++ trunk/ChangeLog	2009-02-10 21:11:25 UTC (rev 3571)
@@ -4,6 +4,11 @@
    src/project.c, src/search.c, src/tools.c, src/vte.c:
    Add a clear icon to the used text entries all over the place
    (will be available with GTK >= 2.16).
+ * plugins/export.c, plugins/filebrowser.c, plugins/htmlchars.c,
+   plugins/vcdiff.c, src/document.c, src/search.c, src/templates.c,
+   src/tools.c, src/treeviews.c, src/utils.c:
+   Small optimisations by moving out function calls of loop break
+   conditions (patch by Frank, thanks).
 
 
 2009-02-08  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>

Modified: trunk/plugins/export.c
===================================================================
--- trunk/plugins/export.c	2009-02-10 21:10:50 UTC (rev 3570)
+++ trunk/plugins/export.c	2009-02-10 21:11:25 UTC (rev 3571)
@@ -339,7 +339,7 @@
 static void write_latex_file(GeanyDocument *doc, const gchar *filename, gboolean use_zoom)
 {
 	GeanyEditor *editor = doc->editor;
-	gint i, style = -1, old_style = 0, column = 0;
+	gint i, doc_len, style = -1, old_style = 0, column = 0;
 	gchar c, c_next, *tmp, *date;
 	/* 0 - fore, 1 - back, 2 - bold, 3 - italic, 4 - font size, 5 - used(0/1) */
 	gint styles[STYLE_MAX + 1][MAX_TYPES];
@@ -361,7 +361,8 @@
 
 	/* read the document and write the LaTeX code */
 	body = g_string_new("");
-	for (i = 0; i < sci_get_length(doc->editor->sci); i++)
+	doc_len = sci_get_length(doc->editor->sci);
+	for (i = 0; i < doc_len; i++)
 	{
 		style = sci_get_style_at(doc->editor->sci, i);
 		c = sci_get_char_at(doc->editor->sci, i);
@@ -546,7 +547,7 @@
 static void write_html_file(GeanyDocument *doc, const gchar *filename, gboolean use_zoom)
 {
 	GeanyEditor *editor = doc->editor;
-	gint i, style = -1, old_style = 0, column = 0;
+	gint i, doc_len, style = -1, old_style = 0, column = 0;
 	gchar c, c_next, *date;
 	/* 0 - fore, 1 - back, 2 - bold, 3 - italic, 4 - font size, 5 - used(0/1) */
 	gint styles[STYLE_MAX + 1][MAX_TYPES];
@@ -580,7 +581,8 @@
 
 	/* read the document and write the HTML body */
 	body = g_string_new("");
-	for (i = 0; i < sci_get_length(doc->editor->sci); i++)
+	doc_len = sci_get_length(doc->editor->sci);
+	for (i = 0; i < doc_len; i++)
 	{
 		style = sci_get_style_at(doc->editor->sci, i);
 		c = sci_get_char_at(doc->editor->sci, i);

Modified: trunk/plugins/filebrowser.c
===================================================================
--- trunk/plugins/filebrowser.c	2009-02-10 21:10:50 UTC (rev 3570)
+++ trunk/plugins/filebrowser.c	2009-02-10 21:11:25 UTC (rev 3571)
@@ -128,9 +128,10 @@
 	if (hide_object_files)
 	{
 		const gchar *exts[] = {".o", ".obj", ".so", ".dll", ".a", ".lib"};
-		guint i;
+		guint i, exts_len;
 
-		for (i = 0; i < G_N_ELEMENTS(exts); i++)
+		exts_len = G_N_ELEMENTS(exts);
+		for (i = 0; i < exts_len; i++)
 		{
 			const gchar *ext = exts[i];
 

Modified: trunk/plugins/htmlchars.c
===================================================================
--- trunk/plugins/htmlchars.c	2009-02-10 21:10:50 UTC (rev 3570)
+++ trunk/plugins/htmlchars.c	2009-02-10 21:11:25 UTC (rev 3571)
@@ -151,7 +151,7 @@
 {
 	GtkTreeIter iter;
 	GtkTreeIter *parent_iter = NULL;
-	guint i;
+	guint i, len;
 
 	gchar *chars[][2] =
 		{
@@ -416,7 +416,8 @@
 			{ "ƒ", "ƒ" },
 		};
 
-	for (i = 0; i < G_N_ELEMENTS(chars); i++)
+	len = G_N_ELEMENTS(chars);
+	for (i = 0; i < len; i++)
 	{
 		if (chars[i][1] == NULL)
 		{	/* add a category */

Modified: trunk/plugins/vcdiff.c
===================================================================
--- trunk/plugins/vcdiff.c	2009-02-10 21:10:50 UTC (rev 3570)
+++ trunk/plugins/vcdiff.c	2009-02-10 21:11:25 UTC (rev 3571)
@@ -180,9 +180,10 @@
 
 static void* find_cmd_env(gint cmd_type, gboolean cmd, const gchar* filename)
 {
-	guint i;
+	guint i, len;
 
-	for (i = 0; i < G_N_ELEMENTS(VC); i++)
+	len = G_N_ELEMENTS(VC);
+	for (i = 0; i < len; i++)
 	{
 		if (check_filename(filename, &VC[i]))
 		{

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2009-02-10 21:10:50 UTC (rev 3570)
+++ trunk/src/document.c	2009-02-10 21:11:25 UTC (rev 3571)
@@ -1073,13 +1073,14 @@
 {
 	const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor);
 	ScintillaObject *sci = editor->sci;
-	gint line;
+	guint line, line_count;
 	gsize tabs = 0, spaces = 0;
 
 	if (detect_tabs_and_spaces(editor))
 		return GEANY_INDENT_TYPE_BOTH;
 
-	for (line = 0; line < sci_get_line_count(sci); line++)
+	line_count = sci_get_line_count(sci);
+	for (line = 0; line < line_count; line++)
 	{
 		gint pos = sci_get_position_from_line(sci, line);
 		gchar c;
@@ -2758,10 +2759,10 @@
  * @return TRUE if all files were saved or had their changes discarded. */
 gboolean document_account_for_unsaved(void)
 {
-	gint p;
-	guint i, len = documents_array->len;
+	guint i, p, page_count, len = documents_array->len;
 
-	for (p = 0; p < gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); p++)
+	page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
+	for (p = 0; p < page_count; p++)
 	{
 		GeanyDocument *doc = document_get_from_page(p);
 

Modified: trunk/src/search.c
===================================================================
--- trunk/src/search.c	2009-02-10 21:10:50 UTC (rev 3570)
+++ trunk/src/search.c	2009-02-10 21:11:25 UTC (rev 3571)
@@ -1154,10 +1154,11 @@
 		}
 		case GEANY_RESPONSE_REPLACE_IN_SESSION:
 		{
-			guint n, count = 0;
+			guint n, page_count, count = 0;
 
 			/* replace in all documents following notebook tab order */
-			for (n = 0; (gint) n < gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); n++)
+			page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
+			for (n = 0; n < page_count; n++)
 			{
 				GeanyDocument *tmp_doc = document_get_from_page(n);
 

Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c	2009-02-10 21:10:50 UTC (rev 3570)
+++ trunk/src/templates.c	2009-02-10 21:11:25 UTC (rev 3571)
@@ -560,7 +560,7 @@
 	gchar *tmp;
 	gchar *prefix;
 	gchar **lines;
-	guint i;
+	guint i, len;
 
 	/* TODO the following switch could be replaced by some intelligent code which reads
 	 * frame_start, frame_end and line_prefix from the filetype definition files */
@@ -675,7 +675,8 @@
 
 	/* add line_prefix to every line of comment_text */
 	lines = g_strsplit(comment_text, "\n", -1);
-	for (i = 0; i < (g_strv_length(lines) - 1); i++)
+	len = g_strv_length(lines) - 1;
+	for (i = 0; i < len; i++)
 	{
 		tmp = lines[i];
 		lines[i] = g_strconcat(prefix, tmp, NULL);

Modified: trunk/src/tools.c
===================================================================
--- trunk/src/tools.c	2009-02-10 21:10:50 UTC (rev 3570)
+++ trunk/src/tools.c	2009-02-10 21:11:25 UTC (rev 3571)
@@ -323,7 +323,8 @@
 	}
 	else
 	{
-		for (i = 0; i < g_strv_length(ui_prefs.custom_commands); i++)
+		guint len = g_strv_length(ui_prefs.custom_commands);
+		for (i = 0; i < len; i++)
 		{
 			if (ui_prefs.custom_commands[i][0] == '\0')
 				continue; /* skip empty fields */
@@ -515,9 +516,10 @@
 	}
 	else
 	{
-		guint i;
+		guint i, len;
 		gint idx = 0;
-		for (i = 0; i < g_strv_length(ui_prefs.custom_commands); i++)
+		len = g_strv_length(ui_prefs.custom_commands);
+		for (i = 0; i < len; i++)
 		{
 			if (ui_prefs.custom_commands[i][0] != '\0') /* skip empty fields */
 			{

Modified: trunk/src/treeviews.c
===================================================================
--- trunk/src/treeviews.c	2009-02-10 21:10:50 UTC (rev 3570)
+++ trunk/src/treeviews.c	2009-02-10 21:11:25 UTC (rev 3571)
@@ -387,11 +387,12 @@
 
 void treeviews_openfiles_update_all()
 {
-	guint i;
+	guint i, page_count;
 	GeanyDocument *doc;
 
 	gtk_tree_store_clear(store_openfiles);
-	for (i = 0; i < (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); i++)
+	page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
+	for (i = 0; i < page_count; i++)
 	{
 		doc = document_get_from_page(i);
 		if (doc == NULL)

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2009-02-10 21:10:50 UTC (rev 3570)
+++ trunk/src/utils.c	2009-02-10 21:11:25 UTC (rev 3571)
@@ -933,11 +933,12 @@
  * Replaces \\, \r, \n, \t and \uXXX by their real counterparts */
 gboolean utils_str_replace_escape(gchar *string)
 {
-	gsize i, j;
+	gsize i, j, len;
 	guint unicodechar;
 
 	j = 0;
-	for (i = 0; i < strlen(string); i++)
+	len = strlen(string);
+	for (i = 0; i < len; i++)
 	{
 		if (string[i]=='\\')
 		{


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list