[前][次][番号順一覧][スレッド一覧]

ruby-changes:32512

From: nobu <ko1@a...>
Date: Tue, 14 Jan 2014 11:48:11 +0900 (JST)
Subject: [ruby-changes:32512] nobu:r44591 (trunk): strscan.c: make string directly

nobu	2014-01-14 11:48:07 +0900 (Tue, 14 Jan 2014)

  New Revision: 44591

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44591

  Log:
    strscan.c: make string directly
    
    * ext/strscan/strscan.c (inspect1): extract intermediate string from
      the buffer directly, like as inspect2.

  Modified files:
    trunk/ext/strscan/strscan.c
Index: ext/strscan/strscan.c
===================================================================
--- ext/strscan/strscan.c	(revision 44590)
+++ ext/strscan/strscan.c	(revision 44591)
@@ -1186,20 +1186,20 @@ strscan_inspect(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/strscan/strscan.c#L1186
 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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]