ruby-changes:29675
From: naruse <ko1@a...>
Date: Mon, 1 Jul 2013 23:12:20 +0900 (JST)
Subject: [ruby-changes:29675] naruse:r41727 (trunk): * template/encdb.h.tmpl: define encoding index macros to use the index
naruse 2013-07-01 23:12:10 +0900 (Mon, 01 Jul 2013) New Revision: 41727 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41727 Log: * template/encdb.h.tmpl: define encoding index macros to use the index statically from C source. Modified files: trunk/ChangeLog trunk/template/encdb.h.tmpl Index: ChangeLog =================================================================== --- ChangeLog (revision 41726) +++ ChangeLog (revision 41727) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Jul 1 23:07:38 2013 NARUSE, Yui <naruse@r...> + + * template/encdb.h.tmpl: define encoding index macros to use the index + statically from C source. + Mon Jul 1 22:57:19 2013 Tanaka Akira <akr@f...> * bignum.c (bary_mul2): New function. Index: template/encdb.h.tmpl =================================================================== --- template/encdb.h.tmpl (revision 41726) +++ template/encdb.h.tmpl (revision 41727) @@ -19,9 +19,14 @@ def check_duplication(defs, name, fn, li https://github.com/ruby/ruby/blob/trunk/template/encdb.h.tmpl#L19 end end -count = 0 lines = [] -encodings = [] +BUILTIN_ENCODINGS = { + 'ASCII-8BIT' => 0, + 'UTF-8' => 1, + 'US-ASCII' => 2, +} +encodings = %w[ASCII-8BIT UTF-8 US-ASCII] # BUILTIN_ENCODINGS.keys is not available on cross compiling and used ruby 1.8 +count = encodings.size defs = {} encdirs = ARGV.dup encdirs << 'enc' if encdirs.empty? @@ -44,6 +49,7 @@ encdirs.each do |encdir| https://github.com/ruby/ruby/blob/trunk/template/encdb.h.tmpl#L49 name = $1 end check_duplication(defs, $1, fn, $.) + next if BUILTIN_ENCODINGS[name] encodings << $1 count += 1 end @@ -52,6 +58,7 @@ encdirs.each do |encdir| https://github.com/ruby/ruby/blob/trunk/template/encdb.h.tmpl#L58 when /^\s*rb_enc_register\(\s*"([^"]+)"/ count += 1 line = nil + encodings << $1 when /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/ raise ArgumentError, '%s:%d: ENC_REPLICATE: %s is not defined yet. (replica %s)' % @@ -73,11 +80,16 @@ encdirs.each do |encdir| https://github.com/ruby/ruby/blob/trunk/template/encdb.h.tmpl#L80 end end end -encodings.each do |e| +encodings.each_with_index do |e, i| %>ENC_DEFINE("<%=e%>"); +#define ENCIDX_<%=e.tr('-', '_')%> <%=i%> % end +% encidx = encodings.size - 1 % lines.each do |line| <%=line%> +% if /^ENC_(?:DUMMY(?:_UNICODE)?|REPLICATE)\(\s*"([^"]+)/ =~ line +#define ENCIDX_<%=$1.tr('-', '_')%> <%=encidx+=1%> +% end % end #define ENCODING_COUNT <%=count%> -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/