diff options
author | ttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-04-04 14:17:19 +0000 |
---|---|---|
committer | ttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-04-04 14:17:19 +0000 |
commit | 289fe2b8ee966544d09e2fc00a7365fa7ecc920d (patch) | |
tree | 513298187164ea4ec4afd53af7dad2d5c3d580fd | |
parent | 5f8d02cbbc1686390d6965adfa12100ddd586109 (diff) |
Get rid of ineffective encoding/decoding procedures.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/dl/lib/dl/import.rb | 64 |
2 files changed, 52 insertions, 17 deletions
@@ -1,3 +1,8 @@ +Thu Apr 4 14:08:52 2002 Takaaki Tateishi <ttate@kt.jaist.ac.jp> + + * ext/dl/lib/dl/import.rb: Get rid of ineffective + encoding/decoding procedures. + Wed Apr 3 15:37:24 2002 Takaaki Tateishi <ttate@kt.jaist.ac.jp> * ext/dl: Add dl/types.rb. diff --git a/ext/dl/lib/dl/import.rb b/ext/dl/lib/dl/import.rb index ee3070c90c..3530953e0c 100644 --- a/ext/dl/lib/dl/import.rb +++ b/ext/dl/lib/dl/import.rb @@ -67,7 +67,7 @@ module DL module_eval [ "def #{mname}(*args)", " sym,rdec,enc,dec = @SYM['#{mname}']", - " args = enc.call(args)", + " args = enc.call(args) if enc", if( $DEBUG ) " p \"[DL] call #{mname} with \#{args.inspect}\"" else @@ -79,8 +79,10 @@ module DL else "" end, - " @retval = rdec.call(r)", - " @args = dec.call(rs)", + " r = rdec.call(r) if rdec", + " rs = dec.call(rs) if dec", + " @retval = r", + " @args = rs", " return @retval", "end", "module_function :#{mname}", @@ -107,21 +109,33 @@ module DL def encode_type(ty) check_type orig_ty = ty - enc = proc{|v| v} - dec = proc{|v| v} + enc = nil + dec = nil @TYDEFS.each{|t1,t2,c1,c2| if( t1.is_a?(String) ) t1 = Regexp.new("^" + t1 + "$") end if( ty =~ t1 ) ty = ty.gsub(t1,t2) - if( c1 ) - conv1 = enc - enc = proc{|v| c1.call(conv1.call(v))} + if( enc ) + if( c1 ) + conv1 = enc + enc = proc{|v| c1.call(conv1.call(v))} + end + else + if( c1 ) + enc = c1 + end end - if( c2 ) - conv2 = dec - dec = proc{|v| c2.call(conv2.call(v))} + if( dec ) + if( c2 ) + conv2 = dec + dec = proc{|v| c2.call(conv2.call(v))} + end + else + if( c2 ) + dec = c2 + end end end } @@ -134,15 +148,31 @@ module DL def encode_types(tys) encty = [] - enc = proc{|v| v} - dec = proc{|v| v} + enc = nil + dec = nil tys.each_with_index{|ty,idx| ty,c1,c2 = encode_type(ty) encty.push(ty) - conv1 = enc - enc = proc{|v| v = conv1.call(v); v[idx] = c1.call(v[idx]); v} - conv2 = dec - dec = proc{|v| v = conv2.call(v); v[idx] = c2.call(v[idx]); v} + if( enc ) + if( c1 ) + conv1 = enc + enc = proc{|v| v = conv1.call(v); v[idx] = c1.call(v[idx]); v} + end + else + if( c1 ) + enc = proc{|v| v[idx] = c1.call(v[idx]); v} + end + end + if( dec ) + if( c2 ) + conv2 = dec + dec = proc{|v| v = conv2.call(v); v[idx] = c2.call(v[idx]); v} + end + else + if( c2 ) + dec = proc{|v| v[idx] = c2.call(v[idx]); v} + end + end } return [encty.join, enc, dec] end |