[vte] [ring] Only write_contents() the part of history that fits in the num rows
- From: Behdad Esfahbod <behdad src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vte] [ring] Only write_contents() the part of history that fits in the num rows
- Date: Thu, 14 Jan 2010 00:49:28 +0000 (UTC)
commit 38b6a46d413247d7acda50f7729048c635ffe23b
Author: Behdad Esfahbod <behdad behdad org>
Date: Wed Jan 13 19:33:34 2010 -0500
[ring] Only write_contents() the part of history that fits in the num rows
src/ring.c | 12 ++++++++++--
src/vtestream-base.h | 12 +++++++++---
src/vtestream-file.h | 19 +++++++++++++++----
src/vtestream.h | 4 +++-
4 files changed, 37 insertions(+), 10 deletions(-)
---
diff --git a/src/ring.c b/src/ring.c
index e5a7e23..34855b1 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -609,8 +609,16 @@ _vte_ring_write_contents (VteRing *ring,
_vte_debug_print(VTE_DEBUG_RING, "Writing contents to GOutputStream.\n");
- if (!_vte_stream_write_contents (ring->text_stream, stream, cancellable, error))
- return FALSE;
+ if (ring->start < ring->writable) {
+ VteRowRecord record;
+ /* XXX what to do in case of error? */
+ if (_vte_ring_read_row_record (ring, &record, ring->start)) {
+ if (!_vte_stream_write_contents (ring->text_stream, stream,
+ record.text_offset,
+ cancellable, error))
+ return FALSE;
+ }
+ }
for (i = ring->writable; i < ring->end; i++) {
if (!_vte_ring_write_row (ring, stream,
diff --git a/src/vtestream-base.h b/src/vtestream-base.h
index 74b7301..913f9c9 100644
--- a/src/vtestream-base.h
+++ b/src/vtestream-base.h
@@ -38,7 +38,9 @@ typedef struct _VteStreamClass {
void (*truncate) (VteStream *stream, gsize offset);
void (*new_page) (VteStream *stream);
gsize (*head) (VteStream *stream);
- gboolean (*write_contents) (VteStream *stream, GOutputStream *output, GCancellable *cancellable, GError **error);
+ gboolean (*write_contents) (VteStream *stream, GOutputStream *output,
+ gsize start_offset,
+ GCancellable *cancellable, GError **error);
} VteStreamClass;
static GType _vte_stream_get_type (void);
@@ -94,7 +96,11 @@ _vte_stream_head (VteStream *stream)
}
gboolean
-_vte_stream_write_contents (VteStream *stream, GOutputStream *output, GCancellable *cancellable, GError **error)
+_vte_stream_write_contents (VteStream *stream, GOutputStream *output,
+ gsize start_offset,
+ GCancellable *cancellable, GError **error)
{
- return VTE_STREAM_GET_CLASS (stream)->write_contents (stream, output, cancellable, error);
+ return VTE_STREAM_GET_CLASS (stream)->write_contents (stream, output,
+ start_offset,
+ cancellable, error);
}
diff --git a/src/vtestream-file.h b/src/vtestream-file.h
index 707877b..bc92d6f 100644
--- a/src/vtestream-file.h
+++ b/src/vtestream-file.h
@@ -93,7 +93,6 @@ _xwrite_contents (gint fd, GOutputStream *output, GCancellable *cancellable, GEr
if (G_UNLIKELY (!fd))
return TRUE;
- lseek (fd, 0, SEEK_SET);
input = g_unix_input_stream_new (fd, FALSE);
ret = -1 != g_output_stream_splice (output, input, G_OUTPUT_STREAM_SPLICE_NONE, cancellable, error);
g_object_unref (input);
@@ -260,12 +259,24 @@ _vte_file_stream_head (VteStream *astream)
}
static gboolean
-_vte_file_stream_write_contents (VteStream *astream, GOutputStream *output, GCancellable *cancellable, GError **error)
+_vte_file_stream_write_contents (VteStream *astream, GOutputStream *output,
+ gsize offset,
+ GCancellable *cancellable, GError **error)
{
VteFileStream *stream = (VteFileStream *) astream;
- return _xwrite_contents (stream->fd[1], output, cancellable, error) &&
- _xwrite_contents (stream->fd[0], output, cancellable, error);
+ if (G_UNLIKELY (offset < stream->offset[1]))
+ return FALSE;
+
+ if (offset < stream->offset[0]) {
+ lseek (stream->fd[1], offset - stream->offset[1], SEEK_SET);
+ if (!_xwrite_contents (stream->fd[1], output, cancellable, error))
+ return FALSE;
+ offset = stream->offset[0];
+ }
+
+ lseek (stream->fd[0], offset - stream->offset[0], SEEK_SET);
+ return _xwrite_contents (stream->fd[0], output, cancellable, error);
}
static void
diff --git a/src/vtestream.h b/src/vtestream.h
index f21e8b0..27a2829 100644
--- a/src/vtestream.h
+++ b/src/vtestream.h
@@ -34,7 +34,9 @@ gboolean _vte_stream_read (VteStream *stream, gsize offset, char *data, gsize le
void _vte_stream_truncate (VteStream *stream, gsize offset);
void _vte_stream_new_page (VteStream *stream);
gsize _vte_stream_head (VteStream *stream);
-gboolean _vte_stream_write_contents (VteStream *stream, GOutputStream *output, GCancellable *cancellable, GError **error);
+gboolean _vte_stream_write_contents (VteStream *stream, GOutputStream *output,
+ gsize start_offset,
+ GCancellable *cancellable, GError **error);
/* Various streams */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]