From f1cb6ea08f8fc897d914fc7c2c23701471657e4f Mon Sep 17 00:00:00 2001 From: drbrain Date: Wed, 30 May 2012 23:20:29 +0000 Subject: * ext/dl/lib/dl/struct.rb (DL::CUnionEntity::size): Fixed ::size to return the size of the union. * test/dl/test_c_union_entity.rb: Test for DL::CUnionEntity::size Reviewed by Aaron Patterson git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/dl/lib/dl/struct.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'ext/dl') diff --git a/ext/dl/lib/dl/struct.rb b/ext/dl/lib/dl/struct.rb index 27f6b42fd2..23f28bbaa3 100644 --- a/ext/dl/lib/dl/struct.rb +++ b/ext/dl/lib/dl/struct.rb @@ -234,17 +234,9 @@ module DL # DL::TYPE_VOIDP]) # => 8 def CUnionEntity.size(types) - size = 0 - types.each_with_index{|t,i| - if( t.is_a?(Array) ) - tsize = PackInfo::SIZE_MAP[t[0]] * t[1] - else - tsize = PackInfo::SIZE_MAP[t] - end - if( tsize > size ) - size = tsize - end - } + types.map { |type, count = 1| + PackInfo::SIZE_MAP[type] * count + }.max end # Given +types+, calculate the necessary offset and for each union member -- cgit v1.2.3