[gnome-latex: 83/205] Execution of the actions: optimization



commit 6a95b75863fbedabf57e0df77a5df9acc2735bf1
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Sat Oct 3 23:07:36 2009 +0200

    Execution of the actions: optimization
    
    To force showing each output line is slow, so after the 200th line the
    forcing is made every 20 lines instead of every line.

 TODO          | 29 ++++------------------------
 src/actions.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 56 insertions(+), 35 deletions(-)
---
diff --git a/TODO b/TODO
index a6dd85c..0c1da39 100644
--- a/TODO
+++ b/TODO
@@ -1,29 +1,6 @@
 TODO LaTeXila
 
-Fri Sep 18, 2009 to Fri Sep 25, 2009
-
-[x] LaTeX menu + new toolbar
-       x font styles: bold, italic, ...
-       x environments: center, flushleft, ...
-       x sectioning: part, chapter, section, ...
-       x size of characters
-       x list environments: itemize, enumerate, description
-       x various: label, ref, pageref, cite, footnote, index
-
-[x] symbol tables
-       x the categories must take the minimum place but the presentation must be nice
-               * homogeneous icons
-               * text under or to the right of the icons?
-
-[x] latex, pdflatex, dvips, dvipdf, ... commands
-       x CMake: use FindLATEX module
-       x preferences
-
-[x] command line option
-       x new document (--new-document)
-
-[x] document tabs
-       x possibility to move the tabs
+Fri Oct 2, 2009 to Fri Oct 9, 2009
 
 [-] undo/redo and the "saved" document property
        - detect when the buffer is the same as in the file currently saved
@@ -35,7 +12,9 @@ Fri Sep 18, 2009 to Fri Sep 25, 2009
                * convert_document ()
                * view_document ()
 
+[-] symbol tables
+       - mathematical sets (N, Z, Q, R, C) in misc math
+
 [x] bugs correction
-       x segfault when changing preferences if no document opened (line numbers and font)
 
 [-] update French translation
diff --git a/src/actions.c b/src/actions.c
index 0b1ba7e..4518abb 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -27,11 +27,14 @@
 #include <glib/gstdio.h>
 #include <gtksourceview/gtksourceview.h>
 
+#include <sys/time.h>
+
 #include "main.h"
 #include "config.h"
 #include "actions.h"
 #include "print.h"
 
+static double difftimeval (struct timeval start, struct timeval end);
 static gchar * get_command_line (gchar **command);
 static void command_running_finished (void);
 static gboolean cb_watch_output_command (GIOChannel *channel,
@@ -40,6 +43,16 @@ static void add_action (gchar *title, gchar *command, gchar *command_output,
                gboolean error);
 
 static GSList *command_output_list = NULL;
+static struct timeval time_start;
+static int nb_lines = 0;
+
+static double
+difftimeval (struct timeval start, struct timeval end)
+{
+    double seconds = end.tv_sec - start.tv_sec;
+    double microsec = end.tv_usec - start.tv_usec;
+    return seconds + microsec / 1000000.0;
+}
 
 static gchar *
 get_command_line (gchar **command)
@@ -104,6 +117,7 @@ command_running_finished (void)
        g_slist_foreach (command_output_list, (GFunc) g_free, NULL);
        g_slist_free (command_output_list);
        command_output_list = NULL;
+       nb_lines = 0;
 }
 
 static gboolean
@@ -112,6 +126,14 @@ cb_watch_output_command (GIOChannel *channel, GIOCondition condition,
 {
        if (condition == G_IO_HUP)
        {
+               struct timeval time_end;
+               gettimeofday (&time_end, NULL);
+               print_info ("time: %f", difftimeval (time_start, time_end));
+
+               // the magic formula
+               while (gtk_events_pending ())
+                       gtk_main_iteration ();
+
                g_io_channel_unref (channel);
                command_running_finished ();
                return FALSE;
@@ -119,7 +141,7 @@ cb_watch_output_command (GIOChannel *channel, GIOCondition condition,
        
        GError *error = NULL;
        gchar *line;
-       g_io_channel_read_line(channel, &line, NULL, NULL, &error);
+       g_io_channel_read_line (channel, &line, NULL, NULL, &error);
 
        if (error != NULL)
        {
@@ -128,17 +150,31 @@ cb_watch_output_command (GIOChannel *channel, GIOCondition condition,
                return FALSE;
        }
 
-       // print the command output line to the log zone
-       print_log_add (latexila.action_log->text_view, line, FALSE);
+       if (line != NULL)
+       {
+               // print the command output line to the log zone
+               print_log_add (latexila.action_log->text_view, line, FALSE);
 
-       // store temporarily the line to the GList
-       // We insert the line at the beginning of the list, so we avoid to traverse
-       // the entire list. The list is reversed when all elements have been added.
-       command_output_list = g_slist_prepend (command_output_list, line);
+               // store temporarily the line to the GList
+               // We insert the line at the beginning of the list, so we avoid to traverse
+               // the entire list. The list is reversed when all elements have been added.
+               command_output_list = g_slist_prepend (command_output_list, line);
+       }
        
-       // the magic formula
-       while (gtk_events_pending ())
-               gtk_main_iteration ();
+       /* Apply the magic formula for the 200 first lines and then every 20 lines.
+        * This is for the fluidity of the output, without that the lines do not
+        * appear directly and it's ugly. But it is very slow, for a command that
+        * execute for example in 10 seconds, it could take 250 seconds (!) if we
+        * apply the magic formula for each line... But with commands that take 1
+        * second or so there is not a big difference.
+        */
+       if (nb_lines < 200 || nb_lines % 20 == 0)
+       {
+               while (gtk_events_pending ())
+                       gtk_main_iteration ();
+       }
+
+       nb_lines++;
 
        return TRUE;
 }
@@ -177,6 +213,10 @@ compile_document (gchar *title, gchar **command)
                gtk_main_iteration ();
 
        /* run the command */
+
+       // time
+       gettimeofday (&time_start, NULL);
+
        gchar *dir = g_path_get_dirname (latexila.active_doc->path);
        GError *error = NULL;
        GPid pid;
@@ -205,6 +245,8 @@ compile_document (gchar *title, gchar **command)
        // UTF-8...
        g_io_channel_set_encoding (out_channel, "ISO-8859-1", &error);
 
+       //g_io_channel_set_flags (out_channel, G_IO_FLAG_NONBLOCK, NULL);
+
        if (error != NULL)
        {
                command_output = g_strdup_printf (


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