[vte/vte-0-34] [stream-file] Keep head value in memory
- From: Behdad Esfahbod <behdad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/vte-0-34] [stream-file] Keep head value in memory
- Date: Fri, 27 Sep 2013 20:11:28 +0000 (UTC)
commit 658c2d4643ec7fb0cdd1ebaedc6377c29a850d21
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 913f9c9..cc7c9f0 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 bc92d6f..8781e45 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 27a2829..29f4fc6 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]