[libgsf] msole: speed up writing a bit.



commit 479ffdbbdd2b626393b007da3351c49204142787
Author: Morten Welinder <terra gnome org>
Date:   Sat Jan 26 15:51:54 2013 -0500

    msole: speed up writing a bit.
    
    Piles of little 4-byte writes can be bad depending on sink.

 ChangeLog               |    5 +++++
 NEWS                    |    1 +
 gsf/gsf-outfile-msole.c |   27 ++++++++++++++++++---------
 3 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 24109f8..840d24a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-01-26  Morten Welinder  <terra gnome org>
+
+	* gsf/gsf-outfile-msole.c (ole_write_bat, ole_write_const): Bunch
+	things up as large writes instead of piles of little ones.
+
 2013-01-19  Valek Filippov  <frob df ru>
 
 	* gsf/gsf-infile-msvba.c,.h (gsf_vba_inflate): Fix for short streams.
diff --git a/NEWS b/NEWS
index 2a276f5..0e7d5b4 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Morten:
 	* Fix error handling of gsf_output_gio_new_for_uri.
 	* Clean out mistaken null checks from g_object_new.
 	* Clean out old glib tests.
+	* Speed up ole writing a bit.
 
 Paolo Bonzini:
 	* Fix gsf_input_dep for msole streams.  [#689706]
diff --git a/gsf/gsf-outfile-msole.c b/gsf/gsf-outfile-msole.c
index 9833bab..3c68f82 100644
--- a/gsf/gsf-outfile-msole.c
+++ b/gsf/gsf-outfile-msole.c
@@ -197,33 +197,42 @@ ole_pad_zero (GsfOutfileMSOle *ole)
 		gsf_output_write (ole->sink, len, zero_buf);
 }
 
+#define CHUNK_SIZE 1024u
+#define FLUSH do { if (bufi) gsf_output_write (sink, bufi * BAT_INDEX_SIZE, buf); bufi = 0; } while (0)
+#define ADD_ITEM(i_) do { GSF_LE_SET_GUINT32 (buf + bufi * BAT_INDEX_SIZE, (i_)); bufi++; if (bufi == CHUNK_SIZE) FLUSH; } while (0)
+
 /* Utility routine to generate a BAT for a file known to be sequential and
  * continuous. */
 static void
 ole_write_bat (GsfOutput *sink, guint32 block, unsigned blocks)
 {
-	guint8 buf [BAT_INDEX_SIZE];
+	guint8 buf[BAT_INDEX_SIZE * CHUNK_SIZE];
+	guint bufi = 0;
 
-/* FIXME FIXME FIXME  optimize this to dump a buffer in 1 step */
 	while (blocks-- > 1) {
 		block++;
-		GSF_LE_SET_GUINT32 (buf, block);
-		gsf_output_write (sink, BAT_INDEX_SIZE, buf);
+		ADD_ITEM (block);
 	}
-	GSF_LE_SET_GUINT32 (buf, BAT_MAGIC_END_OF_CHAIN);
-	gsf_output_write (sink, BAT_INDEX_SIZE, buf);
+	ADD_ITEM (BAT_MAGIC_END_OF_CHAIN);
+	FLUSH;
 }
 
 static void
 ole_write_const (GsfOutput *sink, guint32 value, unsigned n)
 {
-	guint8 buf [BAT_INDEX_SIZE];
+	guint8 buf[BAT_INDEX_SIZE * CHUNK_SIZE];
+	guint bufi = 0;
 
-	GSF_LE_SET_GUINT32 (buf, value);
 	while (n-- > 0)
-		gsf_output_write (sink, BAT_INDEX_SIZE, buf);
+		ADD_ITEM(value);
+
+	FLUSH;
 }
 
+#undef CHUNK_SIZE
+#undef FLUSH
+#undef ADD_ITEM
+
 static void
 ole_pad_bat_unused (GsfOutfileMSOle *ole, unsigned residual)
 {



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