ruby-changes:9700
From: akr <ko1@a...>
Date: Thu, 1 Jan 2009 17:04:21 +0900 (JST)
Subject: [ruby-changes:9700] Ruby:r21241 (trunk): * ext/socket/mkconstants.rb: refine family_to_int.
akr 2009-01-01 17:03:36 +0900 (Thu, 01 Jan 2009) New Revision: 21241 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21241 Log: * ext/socket/mkconstants.rb: refine family_to_int. Modified files: trunk/ChangeLog trunk/ext/socket/mkconstants.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 21240) +++ ChangeLog (revision 21241) @@ -1,3 +1,7 @@ +Thu Jan 1 17:01:50 2009 Tanaka Akira <akr@f...> + + * ext/socket/mkconstants.rb: refine family_to_int. + Thu Jan 1 16:48:07 2009 Tanaka Akira <akr@f...> * ext/socket/mkconstants.rb: generate family_to_int(). Index: ext/socket/mkconstants.rb =================================================================== --- ext/socket/mkconstants.rb (revision 21240) +++ ext/socket/mkconstants.rb (revision 21241) @@ -64,6 +64,17 @@ } end +def each_names_with_len(pat) + h = {} + DEFS.each {|name, default_value| + next if pat !~ name + (h[name.length] ||= []) << name + } + h.keys.sort.each {|len| + yield h[len], len + } +end + result << ERB.new(<<'EOS', nil, '%').result(binding) static void init_constants(VALUE mConst) @@ -89,13 +100,21 @@ static int family_to_int(char *str, int len) { -% each_name(/\A[AP]F_/) {|name| + switch (len) { +% each_names_with_len(/\A[AP]F_/) {|names, len| + case <%=len%>: +% names.each {|name| #ifdef <%=name%> -% size = name.bytesize - if (len == <%=size%> && memcmp(str, <%=c_str name%>, <%=size%>) == 0) return <%=name%>; +% size = name.bytesize + if (memcmp(str, <%=c_str name%>, <%=size%>) == 0) return <%=name%>; #endif -% } - return -1; +% } + return -1; + +% } + default: + return -1; + } } EOS -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/