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

ruby-changes:33548

From: nobu <ko1@a...>
Date: Fri, 18 Apr 2014 23:27:28 +0900 (JST)
Subject: [ruby-changes:33548] nobu:r45629 (trunk): parse.y: shared substring of source

nobu	2014-04-18 23:27:22 +0900 (Fri, 18 Apr 2014)

  New Revision: 45629

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

  Log:
    parse.y: shared substring of source
    
    * parse.y (lex_get_str): return shared sub-string of entire source
      string instead of a partial copy.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 45628)
+++ parse.y	(revision 45629)
@@ -5416,21 +5416,21 @@ must_be_ascii_compatible(VALUE s) https://github.com/ruby/ruby/blob/trunk/parse.y#L5416
 static VALUE
 lex_get_str(struct parser_params *parser, VALUE s)
 {
-    char *beg, *end, *pend;
-    rb_encoding *enc = must_be_ascii_compatible(s);
+    char *beg, *end, *start;
+    long len;
 
     beg = RSTRING_PTR(s);
+    len = RSTRING_LEN(s);
+    start = beg;
     if (lex_gets_ptr) {
-	if (RSTRING_LEN(s) == lex_gets_ptr) return Qnil;
+	if (len == lex_gets_ptr) return Qnil;
 	beg += lex_gets_ptr;
+	len -= lex_gets_ptr;
     }
-    pend = RSTRING_PTR(s) + RSTRING_LEN(s);
-    end = beg;
-    while (end < pend) {
-	if (*end++ == '\n') break;
-    }
-    lex_gets_ptr = end - RSTRING_PTR(s);
-    return rb_enc_str_new(beg, end - beg, enc);
+    end = memchr(beg, '\n', len);
+    if (end) len = ++end - beg;
+    lex_gets_ptr += len;
+    return rb_str_subseq(s, beg - start, len);
 }
 
 static VALUE
@@ -5465,7 +5465,7 @@ parser_compile_string(volatile VALUE vpa https://github.com/ruby/ruby/blob/trunk/parse.y#L5465
     TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser);
     lex_gets = lex_get_str;
     lex_gets_ptr = 0;
-    lex_input = s;
+    lex_input = rb_str_new_frozen(s);
     lex_pbeg = lex_p = lex_pend = 0;
     compile_for_eval = rb_parse_in_eval();
 

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

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