buffer_append_str() allows us to append strings to buffers instead of appending the character by character. To minimize code duplication, buffer_append() now goes through buffer_append_str().
This simplifies implementing multibyte opcode handling in the code emitter. Signed-off-by: Eduard - Gabriel Munteanu <eduard.munte...@linux360.ro> --- include/lib/buffer.h | 7 ++++++- lib/buffer.c | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/lib/buffer.h b/include/lib/buffer.h index 60a3d23..7930aef 100644 --- a/include/lib/buffer.h +++ b/include/lib/buffer.h @@ -27,7 +27,7 @@ struct buffer *alloc_exec_buffer(void); struct buffer *__alloc_buffer(struct buffer_operations *); struct buffer *alloc_buffer(void); void free_buffer(struct buffer *); -int append_buffer(struct buffer *buf, unsigned char); +int append_buffer_str(struct buffer *buf, unsigned char *str, size_t len); static inline void *buffer_ptr(struct buffer *buf) { @@ -44,6 +44,11 @@ static inline size_t buffer_offset(struct buffer *buf) return buf->offset; } +static inline int append_buffer(struct buffer *buf, unsigned char c) +{ + return append_buffer_str(buf, &c, 1); +} + void generic_buffer_free(struct buffer *); #endif diff --git a/lib/buffer.c b/lib/buffer.c index 1da5257..db7a925 100644 --- a/lib/buffer.c +++ b/lib/buffer.c @@ -43,17 +43,20 @@ void free_buffer(struct buffer *buf) free(buf); } -int append_buffer(struct buffer *buf, unsigned char c) +int append_buffer_str(struct buffer *buf, unsigned char *str, size_t len) { - if (buf->offset == buf->size) { - int err = 0; + int err; - if (buf->ops->expand) + if (buf->ops->expand) + while (buf->size - buf->offset < len) { err = buf->ops->expand(buf); - if (err) - return err; - } - buf->buf[buf->offset++] = c; + if (err) + return err; + } + + memcpy(buf->buf + buf->offset, str, len); + buf->offset += len; + return 0; } -- 1.6.0.6 ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel