Revision: 3657 http://trac.macosforge.org/projects/ruby/changeset/3657 Author: lsansonetti@apple.com Date: 2010-02-27 22:51:19 -0800 (Sat, 27 Feb 2010) Log Message: ----------- added bstr_concat() to be used to cat bytes, use it in marshal Modified Paths: -------------- MacRuby/branches/icu/encoding.h MacRuby/branches/icu/marshal.c MacRuby/branches/icu/string.c Modified: MacRuby/branches/icu/encoding.h =================================================================== --- MacRuby/branches/icu/encoding.h 2010-02-28 06:33:40 UTC (rev 3656) +++ MacRuby/branches/icu/encoding.h 2010-02-28 06:51:19 UTC (rev 3657) @@ -311,6 +311,7 @@ VALUE bstr_new(void); VALUE bstr_new_with_data(const uint8_t *bytes, long len); uint8_t *bstr_bytes(VALUE str); +void bstr_concat(VALUE str, const uint8_t *bytes, long len); long bstr_length(VALUE str); void bstr_set_length(VALUE str, long len); void bstr_resize(VALUE str, long capa); Modified: MacRuby/branches/icu/marshal.c =================================================================== --- MacRuby/branches/icu/marshal.c 2010-02-28 06:33:40 UTC (rev 3656) +++ MacRuby/branches/icu/marshal.c 2010-02-28 06:51:19 UTC (rev 3657) @@ -219,7 +219,7 @@ w_nbyte(const char *s, int n, struct dump_arg *arg) { VALUE buf = arg->str; - rb_str_buf_cat(buf, s, n); + bstr_concat(buf, (const uint8_t *)s, n); if (arg->dest && RSTRING_LEN(buf) >= BUFSIZ) { if (arg->taint) OBJ_TAINT(buf); rb_io_write(arg->dest, 0, buf); @@ -898,7 +898,7 @@ w_object(arg->obj, arg->arg, arg->limit); if (arg->arg->dest) { rb_io_write(arg->arg->dest, 0, arg->arg->str); - rb_str_resize(arg->arg->str, 0); + bstr_resize(arg->arg->str, 0); } return 0; } Modified: MacRuby/branches/icu/string.c =================================================================== --- MacRuby/branches/icu/string.c 2010-02-28 06:33:40 UTC (rev 3656) +++ MacRuby/branches/icu/string.c 2010-02-28 06:51:19 UTC (rev 3657) @@ -801,6 +801,18 @@ } static void +str_concat_bytes(rb_str_t *self, const char *bytes, long len) +{ + assert(bytes != NULL && len >= 0); + + const long new_length_in_bytes = self->length_in_bytes + len; + + str_resize_bytes(self, new_length_in_bytes); + memcpy(self->data.bytes + self->length_in_bytes, bytes, len); + self->length_in_bytes = new_length_in_bytes; +} + +static void str_concat_string(rb_str_t *self, rb_str_t *str) { if (str->length_in_bytes == 0) { @@ -814,15 +826,12 @@ str_must_have_compatible_encoding(self, str); str_make_same_format(self, str); - long new_length_in_bytes = self->length_in_bytes + str->length_in_bytes; // TODO: we should maybe merge flags // (if both are ASCII-only, the concatenation is ASCII-only, // though I'm not sure all the tests required are worth doing) str_unset_facultative_flags(self); - str_resize_bytes(self, new_length_in_bytes); - memcpy(self->data.bytes + self->length_in_bytes, str->data.bytes, - str->length_in_bytes); - self->length_in_bytes = new_length_in_bytes; + + str_concat_bytes(self, str->data.bytes, str->length_in_bytes); } static int @@ -3623,6 +3632,8 @@ // ByteString emulation. +#define IS_BSTR(obj) (IS_RSTR(obj) && !str_is_stored_in_uchars(RSTR(obj))) + VALUE rb_str_bstr(VALUE str) { @@ -3636,7 +3647,7 @@ uint8_t * bstr_bytes(VALUE str) { - assert(IS_RSTR(str)); + assert(IS_BSTR(str)); return (uint8_t *)RSTR(str)->data.bytes; } @@ -3658,21 +3669,28 @@ long bstr_length(VALUE str) { - assert(IS_RSTR(str)); + assert(IS_BSTR(str)); return RSTR(str)->length_in_bytes; } void +bstr_concat(VALUE str, const uint8_t *bytes, long len) +{ + assert(IS_BSTR(str)); + str_concat_bytes(RSTR(str), (const char *)bytes, len); +} + +void bstr_resize(VALUE str, long capa) { - assert(IS_RSTR(str)); + assert(IS_BSTR(str)); str_resize_bytes(RSTR(str), capa); } void bstr_set_length(VALUE str, long len) { - assert(IS_RSTR(str)); + assert(IS_BSTR(str)); assert(len <= RSTR(str)->capacity_in_bytes); RSTR(str)->length_in_bytes = len; }
participants (1)
-
source_changes@macosforge.org