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

ruby-changes:7694

From: akr <ko1@a...>
Date: Sun, 7 Sep 2008 18:31:25 +0900 (JST)
Subject: [ruby-changes:7694] Ruby:r19215 (trunk): * tool/transcode-tblgen.rb (ActionMap#generate_info): use a memo to

akr	2008-09-07 18:30:54 +0900 (Sun, 07 Sep 2008)

  New Revision: 19215

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

  Log:
    * tool/transcode-tblgen.rb (ActionMap#generate_info): use a memo to
      avoid duplication for STR1.

  Modified files:
    trunk/ChangeLog
    trunk/tool/transcode-tblgen.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19214)
+++ ChangeLog	(revision 19215)
@@ -1,3 +1,8 @@
+Sun Sep  7 18:28:05 2008  Tanaka Akira  <akr@f...>
+
+	* tool/transcode-tblgen.rb (ActionMap#generate_info): use a memo to
+	  avoid duplication for STR1.
+
 Sun Sep  7 18:10:28 2008  Tanaka Akira  <akr@f...>
 
 	* transcode_data.h (STR1): defined for a string up to 255 bytes.
Index: tool/transcode-tblgen.rb
===================================================================
--- tool/transcode-tblgen.rb	(revision 19214)
+++ tool/transcode-tblgen.rb	(revision 19215)
@@ -277,6 +277,8 @@
     code
   end
 
+  StrMemo = {}
+
   def generate_info(info)
     case info
     when :nomap
@@ -302,13 +304,19 @@
     when /\A(f[0-7])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])\z/i
       "o4(0x#$1,0x#$2,0x#$3,0x#$4)"
     when /\A([0-9a-f][0-9a-f]){0,255}\z/i
-      bytes = info
-      len = info.length/2
-      size = @bytes_code.length
-      @bytes_code.insert_at_last(1 + len,
-        "\#define str1_#{size} makeSTR1(#{size})\n" +
-        "    #{len}," + info.gsub(/../, ' 0x\&,') + "\n")
-      "str1_#{size}"
+      bytes = info.upcase
+      if n = StrMemo[bytes]
+        n
+      else
+        len = info.length/2
+        size = @bytes_code.length
+        @bytes_code.insert_at_last(1 + len,
+          "\#define str1_#{size} makeSTR1(#{size})\n" +
+          "    #{len}," + info.gsub(/../, ' 0x\&,') + "\n")
+        n = "str1_#{size}"
+        StrMemo[bytes] = n
+        n
+      end
     when /\A\/\*BYTE_LOOKUP\*\// # pointer to BYTE_LOOKUP structure
       $'.to_s
     else

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

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