[vte] Use GByteArray for VteBuffer
- From: Behdad Esfahbod <behdad src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vte] Use GByteArray for VteBuffer
- Date: Thu, 20 Aug 2009 19:12:57 +0000 (UTC)
commit f168a8a2e6b266e980d15c2af023ce7ea1f15394
Author: Behdad Esfahbod <behdad behdad org>
Date: Thu Aug 20 15:09:20 2009 -0400
Use GByteArray for VteBuffer
The implementation was the same. Keep the abstraction though, since
VteBuffer may want to implement O(1) _consume() in the future.
src/Makefile.am | 7 +--
src/buffer.c | 156 -------------------------------------------------------
src/buffer.h | 25 ++++-----
src/interpret.c | 2 +-
src/iso2022.c | 2 +-
src/vte.c | 16 +++---
src/vteconv.c | 6 +-
src/vteseq.c | 2 +-
8 files changed, 25 insertions(+), 191 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 97a0ca6..53c7183 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,7 +30,6 @@ EXTRA_libvte_la_SOURCES = \
$(NULL)
libvte_la_SOURCES = \
- buffer.c \
buffer.h \
caps.c \
caps.h \
@@ -176,7 +175,6 @@ reflect_vte_SOURCES = reflect.c
reflect_vte_LDADD = libvte.la $(VTE_LIBS)
interpret_SOURCES = \
- buffer.c \
buffer.h \
caps.c \
caps.h \
@@ -204,7 +202,6 @@ interpret_CFLAGS = $(GTK_CFLAGS)
interpret_LDADD = $(GTK_LIBS)
iso2022_SOURCES = \
- buffer.c \
buffer.h \
caps.c \
caps.h \
@@ -235,7 +232,6 @@ slowcat_SOURCES = \
slowcat.c
table_SOURCES = \
- buffer.c \
buffer.h \
caps.c \
caps.h \
@@ -258,7 +254,6 @@ table_LDADD = $(VTE_LIBS)
trie_SOURCES = \
trie.c \
trie.h \
- buffer.c \
buffer.h \
caps.c \
caps.h \
@@ -285,7 +280,7 @@ pty_CPPFLAGS = -DPTY_MAIN -DLIBEXECDIR='"$(libexecdir)"'
reaper_SOURCES = reaper.c reaper.h debug.c debug.h marshal.c marshal.h
reaper_CPPFLAGS = -DREAPER_MAIN -DLOCALEDIR='"$(localedir)"'
-vteconv_SOURCES = buffer.c buffer.h debug.c debug.h vteconv.c vteconv.h
+vteconv_SOURCES = buffer.h debug.c debug.h vteconv.c vteconv.h
vteconv_CPPFLAGS = -DVTECONV_MAIN
vteconv_CFLAGS = $(VTE_CFLAGS)
vteconv_LDADD = $(VTE_LIBS)
diff --git a/src/buffer.h b/src/buffer.h
index cc22d77..7cfee85 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -24,24 +24,19 @@
#define vte_buffer_h_included
-#include <sys/types.h>
+#include <glib.h>
G_BEGIN_DECLS
-typedef struct {
- /* public */
- unsigned char *bytes;
- /* private stuff is hidden */
-} VteBuffer;
-
-VteBuffer* _vte_buffer_new(void);
-void _vte_buffer_free(VteBuffer *buffer);
-void _vte_buffer_append(VteBuffer *buffer,
- gconstpointer bytes, size_t length);
-size_t _vte_buffer_length(VteBuffer *buffer);
-void _vte_buffer_consume(VteBuffer *buffer, size_t length);
-void _vte_buffer_clear(VteBuffer *buffer);
-void _vte_buffer_set_minimum_size(VteBuffer *buffer, size_t length);
+typedef GByteArray VteBuffer;
+
+#define _vte_buffer_new g_byte_array_new
+#define _vte_buffer_free(B) g_byte_array_free (B, TRUE)
+#define _vte_buffer_append g_byte_array_append
+#define _vte_buffer_length(B) ((B)->len)
+#define _vte_buffer_consume(B, length) g_byte_array_remove_range (B, 0, length)
+#define _vte_buffer_clear(B) g_byte_array_set_size (B, 0)
+#define _vte_buffer_set_minimum_size(B, length) g_byte_array_set_size (B, MAX ((length), (B)->len))
G_END_DECLS
diff --git a/src/interpret.c b/src/interpret.c
index ab5d9b8..cfdbd44 100644
--- a/src/interpret.c
+++ b/src/interpret.c
@@ -87,7 +87,7 @@ main(int argc, char **argv)
while (fread(&b, 1, 1, infile) == 1) {
_vte_buffer_append(buffer, &b, 1);
}
- _vte_iso2022_process(subst, buffer->bytes,
+ _vte_iso2022_process(subst, buffer->data,
_vte_buffer_length(buffer), array);
i = 0;
diff --git a/src/iso2022.c b/src/iso2022.c
index 12593b5..43069b9 100644
--- a/src/iso2022.c
+++ b/src/iso2022.c
@@ -1143,7 +1143,7 @@ process_cdata(struct _vte_iso2022_state *state, const guchar *cdata, gsize lengt
inbytes = length;
_vte_buffer_set_minimum_size(state->buffer,
sizeof(gunichar) * length * 2);
- buf = (gunichar *)state->buffer->bytes;
+ buf = (gunichar *)state->buffer->data;
outbuf = buf;
outbytes = sizeof(gunichar) * length * 2;
do {
diff --git a/src/vte.c b/src/vte.c
index 0906e9e..36b0286 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -2302,7 +2302,7 @@ vte_terminal_set_encoding(VteTerminal *terminal, const char *codeset)
if ((_vte_buffer_length(terminal->pvt->outgoing) > 0) &&
(old_codeset != NULL)) {
/* Convert back to UTF-8. */
- obuf1 = g_convert((gchar *)terminal->pvt->outgoing->bytes,
+ obuf1 = g_convert((gchar *)terminal->pvt->outgoing->data,
_vte_buffer_length(terminal->pvt->outgoing),
"UTF-8",
old_codeset,
@@ -4364,18 +4364,18 @@ vte_terminal_io_write(GIOChannel *channel,
fd = g_io_channel_unix_get_fd(channel);
- count = write(fd, terminal->pvt->outgoing->bytes,
+ count = write(fd, terminal->pvt->outgoing->data,
_vte_buffer_length(terminal->pvt->outgoing));
if (count != -1) {
_VTE_DEBUG_IF (VTE_DEBUG_IO) {
gssize i;
for (i = 0; i < count; i++) {
g_printerr("Wrote %c%c\n",
- ((guint8)terminal->pvt->outgoing->bytes[i]) >= 32 ?
+ ((guint8)terminal->pvt->outgoing->data[i]) >= 32 ?
' ' : '^',
- ((guint8)terminal->pvt->outgoing->bytes[i]) >= 32 ?
- terminal->pvt->outgoing->bytes[i] :
- ((guint8)terminal->pvt->outgoing->bytes[i]) + 64);
+ ((guint8)terminal->pvt->outgoing->data[i]) >= 32 ?
+ terminal->pvt->outgoing->data[i] :
+ ((guint8)terminal->pvt->outgoing->data[i]) + 64);
}
}
_vte_buffer_consume(terminal->pvt->outgoing, count);
@@ -4419,7 +4419,7 @@ vte_terminal_send(VteTerminal *terminal, const char *encoding,
ibuf = data;
ocount = ((length + 1) * VTE_UTF8_BPC) + 1;
_vte_buffer_set_minimum_size(terminal->pvt->conv_buffer, ocount);
- obuf = obufptr = terminal->pvt->conv_buffer->bytes;
+ obuf = obufptr = terminal->pvt->conv_buffer->data;
if (_vte_conv(conv, &ibuf, &icount, &obuf, &ocount) == (gsize)-1) {
g_warning(_("Error (%s) converting data for child, dropping."),
@@ -13288,7 +13288,7 @@ vte_terminal_set_word_chars(VteTerminal *terminal, const char *spec)
ibuf = ibufptr = (guchar *)g_strdup(spec);
olen = (ilen + 1) * sizeof(gunichar);
_vte_buffer_set_minimum_size(terminal->pvt->conv_buffer, olen);
- obuf = obufptr = terminal->pvt->conv_buffer->bytes;
+ obuf = obufptr = terminal->pvt->conv_buffer->data;
wbuf = (gunichar*) obuf;
wbuf[ilen] = '\0';
_vte_conv(conv, (const guchar **)&ibuf, &ilen, &obuf, &olen);
diff --git a/src/vteconv.c b/src/vteconv.c
index a5fcb30..2b91d33 100644
--- a/src/vteconv.c
+++ b/src/vteconv.c
@@ -252,14 +252,14 @@ _vte_conv(VteConv converter,
(char_count + 1) * VTE_UTF8_BPC);
/* Convert the incoming text. */
g = (gunichar*) *inbuf;
- p = converter->in_scratch->bytes;
+ p = converter->in_scratch->data;
end = p + (char_count + 1) * VTE_UTF8_BPC;
for (i = 0; i < char_count; i++) {
p += g_unichar_to_utf8(g[i], (gchar *)p);
g_assert(p <= end);
}
/* Update our working pointers. */
- work_inbuf_start = converter->in_scratch->bytes;
+ work_inbuf_start = converter->in_scratch->data;
work_inbuf_working = work_inbuf_start;
work_inbytes = p - work_inbuf_start;
}
@@ -269,7 +269,7 @@ _vte_conv(VteConv converter,
work_outbytes = *outbytes_left * VTE_UTF8_BPC;
_vte_buffer_set_minimum_size(converter->out_scratch,
work_outbytes);
- work_outbuf_start = converter->out_scratch->bytes;
+ work_outbuf_start = converter->out_scratch->data;
work_outbuf_working = work_outbuf_start;
}
diff --git a/src/vteseq.c b/src/vteseq.c
index 072b19a..92c9227 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -183,7 +183,7 @@ vte_ucs4_to_utf8 (VteTerminal *terminal, const guchar *in)
outlen = (inlen * VTE_UTF8_BPC) + 1;
_vte_buffer_set_minimum_size (terminal->pvt->conv_buffer, outlen);
- buf = bufptr = terminal->pvt->conv_buffer->bytes;
+ buf = bufptr = terminal->pvt->conv_buffer->data;
if (_vte_conv (conv, &in, &inlen, &buf, &outlen) == (size_t) -1) {
_vte_debug_print (VTE_DEBUG_IO,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]