[gimp/gimp-2-8] Bug 686862 - Seek less when saving XCF files
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-8] Bug 686862 - Seek less when saving XCF files
- Date: Fri, 10 Apr 2015 10:52:39 +0000 (UTC)
commit 7b7921a3198fee59d7a58824c4198575ddaf0907
Author: Michael Natterer <mitch gimp org>
Date: Mon Apr 6 20:01:39 2015 +0200
Bug 686862 - Seek less when saving XCF files
Get rid of most seeking by writing the tile offsets to a table in
memory, instead of directly to the file after each tile. Only seek
back after writing all tiles, in order to save the entire table at
once.
(cherry picked from commit 744eeb8e1a70270a58b44b19f515dd58f2964f12)
app/xcf/xcf-save.c | 34 +++++++++++++++++++---------------
1 files changed, 19 insertions(+), 15 deletions(-)
---
diff --git a/app/xcf/xcf-save.c b/app/xcf/xcf-save.c
index b6bcdd5..0e713ed 100644
--- a/app/xcf/xcf-save.c
+++ b/app/xcf/xcf-save.c
@@ -1384,6 +1384,8 @@ xcf_save_level (XcfInfo *info,
TileManager *level,
GError **error)
{
+ guint32 *offset_table;
+ guint32 *next_offset;
guint32 saved_pos;
guint32 offset;
guint32 width;
@@ -1407,7 +1409,15 @@ xcf_save_level (XcfInfo *info,
ntiles = level->ntile_rows * level->ntile_cols;
- /* 'saved_pos' is the next slot in the offset table */
+ /* allocate an offset table so we don't have to seek back after each
+ * tile, see bug #686862. allocate ntiles + 1 slots because a zero
+ * offset indicates the offset table's end.
+ */
+ offset_table = g_alloca ((ntiles + 1) * sizeof (gint32));
+ memset (offset_table, 0, (ntiles + 1) * sizeof (gint32));
+ next_offset = offset_table;
+
+ /* 'saved_pos' is the offset of the tile offset table */
saved_pos = info->cp;
/* write an empty offset table */
@@ -1420,17 +1430,8 @@ xcf_save_level (XcfInfo *info,
{
for (i = 0; i < ntiles; i++)
{
- /* seek back to the next slot in the offset table and write the
- * offset of the tile
- */
- xcf_check_error (xcf_seek_pos (info, saved_pos, error));
- xcf_write_int32_check_error (info, &offset, 1);
-
- /* remember the next slot in the offset table */
- saved_pos = info->cp;
-
- /* seek to the tile offset and save the tile */
- xcf_check_error (xcf_seek_pos (info, offset, error));
+ /* store the offset in the table and increment the next pointer */
+ *next_offset++ = offset;
/* write out the tile. */
switch (info->compression)
@@ -1457,9 +1458,12 @@ xcf_save_level (XcfInfo *info,
g_free (rlebuf);
- /* there is already a '0' at the end of the offset table to indicate
- * the end of the tile offsets
- */
+ /* seek back to the offset table and write it */
+ xcf_check_error (xcf_seek_pos (info, saved_pos, error));
+ xcf_write_int32_check_error (info, offset_table, ntiles + 1);
+
+ /* seek to the end of the file */
+ xcf_check_error (xcf_seek_pos (info, offset, error));
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]