[ruby-cvs:61261] nobu:r54100 (trunk): optimize named capture assignment

nobu at ruby-lang.org nobu at ruby-lang.org
Mon Mar 14 16:53:39 JST 2016


nobu	2016-03-14 16:53:39 +0900 (Mon, 14 Mar 2016)

  New Revision: 54100

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

  Log:
    optimize named capture assignment
    
    * compile.c (compile_named_capture_assign): optimize named capture
      assignments, by replacing repeating global variable accesses
      with `dup`, and by returning the matched result instead of
      re-getting it from the MatchData.
    
    * parse.y (reg_named_capture_assign_gen): build just assignment
      nodes for the optimization.
    
    ex. `/(?<x>.)/ =~ "bar"`
    
    - old
      ```
      0000 putstring        "bar"
      0002 opt_regexpmatch1 /(?<x>.)/
      0004 pop
      0005 getglobal        $~
      0007 branchunless     25
      0009 getglobal        $~
      0011 putobject        :x
      0013 opt_aref         <callinfo!mid:[], argc:1, ARGS_SIMPLE>
      0016 setlocal_OP__WC__0 2
      0018 getglobal        $~
      0020 putobject_OP_INT2FIX_O_0_C_
      0021 opt_send_without_block <callinfo!mid:begin, argc:1, ARGS_SIMPLE>
      0024 leave
      0025 putobject        nil
      0027 setlocal_OP__WC__0 2
      0029 putobject        nil
      0031 leave
      ```
    
    - new
      ```
      0000 putstring        "bar"
      0002 opt_regexpmatch1 /(?<x>.)/
      0004 getglobal        $~
      0006 dup
      0007 branchunless     14
      0009 putobject        :x
      0011 opt_aref         <callinfo!mid:[], argc:1, ARGS_SIMPLE>
      0014 setlocal_OP__WC__0 2
      0016 leave
      ```

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/node.c
    trunk/parse.y


More information about the ruby-cvs mailing list