[vte/vte-next] [stream-file] Keep head value in memory



commit 317dede20b21e902c90b3f0090564614a47b3e3c
Author: Behdad Esfahbod <behdad behdad org>
Date:   Fri Sep 27 16:00:27 2013 -0400

    [stream-file] Keep head value in memory
    
    Reduces syscalls.
    
    Part of Bug 637275 - Use pread/pwrite() in vtestream-file.h if available

 src/vtestream-base.h |    4 ++--
 src/vtestream-file.h |   17 ++++++++---------
 src/vtestream.h      |    2 +-
 3 files changed, 11 insertions(+), 12 deletions(-)
---
diff --git a/src/vtestream-base.h b/src/vtestream-base.h
index d231896..2bc57ff 100644
--- a/src/vtestream-base.h
+++ b/src/vtestream-base.h
@@ -65,10 +65,10 @@ _vte_stream_reset (VteStream *stream, gsize offset)
        VTE_STREAM_GET_CLASS (stream)->reset (stream, offset);
 }
 
-gsize
+void
 _vte_stream_append (VteStream *stream, const char *data, gsize len)
 {
-       return VTE_STREAM_GET_CLASS (stream)->append (stream, data, len);
+       VTE_STREAM_GET_CLASS (stream)->append (stream, data, len);
 }
 
 gboolean
diff --git a/src/vtestream-file.h b/src/vtestream-file.h
index 4b6433e..28f5281 100644
--- a/src/vtestream-file.h
+++ b/src/vtestream-file.h
@@ -111,6 +111,7 @@ typedef struct _VteFileStream {
        /* The first fd/offset is for the write head, second is for last page */
        gint fd[2];
        gsize offset[2];
+       gsize head;
 } VteFileStream;
 
 typedef VteStreamClass VteFileStreamClass;
@@ -169,10 +170,10 @@ _vte_file_stream_reset (VteStream *astream, gsize offset)
        if (stream->fd[0]) _xtruncate (stream->fd[0], 0);
        if (stream->fd[1]) _xtruncate (stream->fd[1], 0);
 
-       stream->offset[0] = stream->offset[1] = offset;
+       stream->head = stream->offset[0] = stream->offset[1] = offset;
 }
 
-static gsize
+static void
 _vte_file_stream_append (VteStream *astream, const char *data, gsize len)
 {
        VteFileStream *stream = (VteFileStream *) astream;
@@ -180,10 +181,9 @@ _vte_file_stream_append (VteStream *astream, const char *data, gsize len)
 
        _vte_file_stream_ensure_fd0 (stream);
 
-       ret = lseek (stream->fd[0], 0, SEEK_END);
+       lseek (stream->fd[0], 0, SEEK_END);
        _xwrite (stream->fd[0], data, len);
-
-       return stream->offset[0] + ret;
+       stream->head += len;
 }
 
 static gboolean
@@ -233,6 +233,8 @@ _vte_file_stream_truncate (VteStream *astream, gsize offset)
        } else {
                _xtruncate (stream->fd[0], offset - stream->offset[0]);
        }
+
+       stream->head = offset;
 }
 
 static void
@@ -252,10 +254,7 @@ _vte_file_stream_head (VteStream *astream)
 {
        VteFileStream *stream = (VteFileStream *) astream;
 
-       if (stream->fd[0])
-               return stream->offset[0] + lseek (stream->fd[0], 0, SEEK_END);
-       else
-               return stream->offset[0];
+       return stream->head;
 }
 
 static gboolean
diff --git a/src/vtestream.h b/src/vtestream.h
index 01e97df..1a7ec05 100644
--- a/src/vtestream.h
+++ b/src/vtestream.h
@@ -29,7 +29,7 @@ G_BEGIN_DECLS
 typedef struct _VteStream VteStream;
 
 void _vte_stream_reset (VteStream *stream, gsize offset);
-gsize _vte_stream_append (VteStream *stream, const char *data, gsize len);
+void _vte_stream_append (VteStream *stream, const char *data, gsize len);
 gboolean _vte_stream_read (VteStream *stream, gsize offset, char *data, gsize len);
 void _vte_stream_truncate (VteStream *stream, gsize offset);
 void _vte_stream_new_page (VteStream *stream);


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