summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--pack.c11
-rw-r--r--string.c15
3 files changed, 29 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 31b7dba63d..c21f777fc7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Mon Aug 6 23:47:46 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
+
+ * pack.c (pack_unpack): associates p/P strings once at
+ last(reverted to 1.26).
+
+ * string.c (rb_str_associate): associates an Array at once, not
+ but a String. realloc's when str_buf.
+
Mon Aug 6 14:31:37 2001 Usaku Nakamura <usa@ruby-lang.org>
* numeric.c (num_divmod): fix typo.
diff --git a/pack.c b/pack.c
index caf829e22f..18de622c2b 100644
--- a/pack.c
+++ b/pack.c
@@ -331,7 +331,7 @@ pack_pack(ary, fmt)
static char *nul10 = "\0\0\0\0\0\0\0\0\0\0";
static char *spc10 = " ";
char *p, *pend;
- VALUE res, from;
+ VALUE res, from, associates = 0;
char type;
int items, len, idx;
char *ptr;
@@ -872,7 +872,10 @@ pack_pack(ary, fmt)
StringValue(from);
t = RSTRING(from)->ptr;
}
- rb_str_associate(res, from);
+ if (!associates) {
+ associates = rb_ary_new();
+ }
+ rb_ary_push(associates, from);
rb_str_buf_cat(res, (char*)&t, sizeof(char*));
}
break;
@@ -927,6 +930,10 @@ pack_pack(ary, fmt)
break;
}
}
+
+ if (associates) {
+ rb_str_associate(res, associates);
+ }
return res;
}
diff --git a/string.c b/string.c
index 326b9626b1..ec1a31362d 100644
--- a/string.c
+++ b/string.c
@@ -203,13 +203,22 @@ rb_str_associate(str, add)
VALUE str, add;
{
if (FL_TEST(str, STR_NO_ORIG|STR_ASSOC) != (STR_NO_ORIG|STR_ASSOC)) {
- if (RSTRING(str)->orig) {
+ if (FL_TEST(str, STR_NO_ORIG)) {
+ /* str_buf */
+ if (FIX2LONG(RSTRING(str)->orig) != RSTRING(str)->len) {
+ REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len + 1);
+ }
+ }
+ else if (RSTRING(str)->orig) {
rb_str_modify(str);
}
- RSTRING(str)->orig = rb_ary_new();
+ RSTRING(str)->orig = add;
FL_SET(str, STR_NO_ORIG|STR_ASSOC);
}
- rb_ary_push(RSTRING(str)->orig, add);
+ else {
+ /* already associated */
+ rb_ary_concat(RSTRING(str)->orig, add);
+ }
}
VALUE