summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--string.c34
2 files changed, 20 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 150716715..2fc6dffb6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Jan 11 23:22:31 2008 Tanaka Akira <akr@fsij.org>
+
+ * string.c (string.c): call rb_str_buf_append to update encoding of
+ str1, even if str2 is empty.
+
Fri Jan 11 20:20:16 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* proc.c (proc_mark): needs to mark the receiver too. a patch from
diff --git a/string.c b/string.c
index c03143181..9b7945375 100644
--- a/string.c
+++ b/string.c
@@ -1194,26 +1194,22 @@ rb_str_append(VALUE str, VALUE str2)
int cr, cr2;
StringValue(str2);
- if (RSTRING_LEN(str2) > 0) {
- if (STR_ASSOC_P(str)) {
- long len = RSTRING_LEN(str)+RSTRING_LEN(str2);
- enc = rb_enc_check(str, str2);
- cr = ENC_CODERANGE(str);
- if ((cr2 = ENC_CODERANGE(str2)) > cr) cr = cr2;
- rb_str_modify(str);
- REALLOC_N(RSTRING(str)->as.heap.ptr, char, len+1);
- memcpy(RSTRING(str)->as.heap.ptr + RSTRING(str)->as.heap.len,
- RSTRING_PTR(str2), RSTRING_LEN(str2)+1);
- RSTRING(str)->as.heap.len = len;
- rb_enc_associate(str, enc);
- ENC_CODERANGE_SET(str, cr);
- }
- else {
- return rb_str_buf_append(str, str2);
- }
+ if (RSTRING_LEN(str2) > 0 && STR_ASSOC_P(str)) {
+ long len = RSTRING_LEN(str)+RSTRING_LEN(str2);
+ enc = rb_enc_check(str, str2);
+ cr = ENC_CODERANGE(str);
+ if ((cr2 = ENC_CODERANGE(str2)) > cr) cr = cr2;
+ rb_str_modify(str);
+ REALLOC_N(RSTRING(str)->as.heap.ptr, char, len+1);
+ memcpy(RSTRING(str)->as.heap.ptr + RSTRING(str)->as.heap.len,
+ RSTRING_PTR(str2), RSTRING_LEN(str2)+1);
+ RSTRING(str)->as.heap.len = len;
+ rb_enc_associate(str, enc);
+ ENC_CODERANGE_SET(str, cr);
+ OBJ_INFECT(str, str2);
+ return str;
}
- OBJ_INFECT(str, str2);
- return str;
+ return rb_str_buf_append(str, str2);
}