summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-14 02:48:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-14 02:48:07 +0000
commit747e3c73e02a510f302116a491bc2359e156c407 (patch)
tree28a6debebe2e82c6bff7feb37d73da03aea8cbf2 /ext
parentab4e0ab45802926db03bb2d10b337fa3659bea63 (diff)
strscan.c: make string directly
* ext/strscan/strscan.c (inspect1): extract intermediate string from the buffer directly, like as inspect2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/strscan/strscan.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c
index 177cfdd..a62616c 100644
--- a/ext/strscan/strscan.c
+++ b/ext/strscan/strscan.c
@@ -1186,20 +1186,20 @@ strscan_inspect(VALUE self)
static VALUE
inspect1(struct strscanner *p)
{
- char buf[BUFSIZE];
- char *bp = buf;
+ VALUE str;
long len;
if (p->curr == 0) return rb_str_new2("");
if (p->curr > INSPECT_LENGTH) {
- strcpy(bp, "..."); bp += 3;
- len = INSPECT_LENGTH;
+ str = rb_str_new_cstr("...");
+ len = INSPECT_LENGTH;
}
else {
- len = p->curr;
+ str = rb_str_new(0, 0);
+ len = p->curr;
}
- memcpy(bp, CURPTR(p) - len, len); bp += len;
- return rb_str_dump(rb_str_new(buf, bp - buf));
+ rb_str_cat2(str, CURPTR(p) - len, len);
+ return rb_str_dump(str);
}
static VALUE