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

ruby-changes:39273

From: nobu <ko1@a...>
Date: Thu, 23 Jul 2015 14:14:56 +0900 (JST)
Subject: [ruby-changes:39273] nobu:r51354 (trunk): string.c: trivial optimizations

nobu	2015-07-23 14:14:35 +0900 (Thu, 23 Jul 2015)

  New Revision: 51354

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

  Log:
    string.c: trivial optimizations
    
    * string.c (rb_str_new_frozen, str_make_independent_expand):
      trivial peephole optimizations.

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 51353)
+++ string.c	(revision 51354)
@@ -973,8 +973,9 @@ rb_str_new_frozen(VALUE orig) https://github.com/ruby/ruby/blob/trunk/string.c#L973
     else {
 	if (FL_TEST(orig, STR_SHARED)) {
 	    VALUE shared = RSTRING(orig)->as.heap.aux.shared;
-	    long ofs = RSTRING_PTR(orig) - RSTRING_PTR(shared);
-	    long rest = RSTRING_LEN(shared) - ofs - RSTRING_LEN(orig);
+	    long ofs = RSTRING(orig)->as.heap.ptr - RSTRING(shared)->as.heap.ptr;
+	    long rest = RSTRING(shared)->as.heap.len - ofs - RSTRING(orig)->as.heap.len;
+	    assert(!STR_EMBED_P(shared));
 	    assert(OBJ_FROZEN(shared));
 
 	    if ((ofs > 0) || (rest > 0) ||
@@ -1623,6 +1624,7 @@ static void https://github.com/ruby/ruby/blob/trunk/string.c#L1624
 str_make_independent_expand(VALUE str, long expand)
 {
     char *ptr;
+    const char *oldptr;
     long len = RSTRING_LEN(str);
     const int termlen = TERM_LEN(str);
     long capa = len + expand;
@@ -1639,8 +1641,9 @@ str_make_independent_expand(VALUE str, l https://github.com/ruby/ruby/blob/trunk/string.c#L1641
     }
 
     ptr = ALLOC_N(char, capa + termlen);
-    if (RSTRING_PTR(str)) {
-	memcpy(ptr, RSTRING_PTR(str), len);
+    oldptr = RSTRING_PTR(str);
+    if (oldptr) {
+	memcpy(ptr, oldptr, len);
     }
     STR_SET_NOEMBED(str);
     FL_UNSET(str, STR_SHARED|STR_NOFREE);

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

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