diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-01 08:03:36 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-01 08:03:36 +0000 |
| commit | 5147dc2075760828a8041c28445dca21fc1119d8 (patch) | |
| tree | f860c4fb831f9b9afba8a4e10f47378fe1d1a7a6 /ext | |
| parent | 79060f6116545135339d75f2f6f24e5e474536c0 (diff) | |
| download | ruby-5147dc2075760828a8041c28445dca21fc1119d8.tar.gz ruby-5147dc2075760828a8041c28445dca21fc1119d8.tar.xz ruby-5147dc2075760828a8041c28445dca21fc1119d8.zip | |
* ext/socket/mkconstants.rb: refine family_to_int.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@21241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/socket/mkconstants.rb | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb index 64743d723..e11c9c344 100644 --- a/ext/socket/mkconstants.rb +++ b/ext/socket/mkconstants.rb @@ -64,6 +64,17 @@ def each_name(pat) } 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 @@ init_constants(VALUE mConst) 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 |
