fix padding to only consider layout (1 word)
This commit is contained in:
parent
ca1dc36e3d
commit
0f8f0a681c
@ -2,10 +2,10 @@
|
|||||||
module Padding
|
module Padding
|
||||||
|
|
||||||
# objects only come in lengths of multiple of 8 words
|
# objects only come in lengths of multiple of 8 words
|
||||||
# but there is a constant overhead of 2 words, one for type, one for layout
|
# but there is a constant overhead of 1 words for layout
|
||||||
# and as we would have to subtract 1 to make it work without overhead, we now have to add 7
|
# and as we would have to subtract 1 to make it work without overhead, we now have to add 7
|
||||||
def padded len
|
def padded len
|
||||||
a = 32 * (1 + (len + 7)/32 )
|
a = 32 * (1 + (len + 3)/32 )
|
||||||
#puts "#{a} for #{len}"
|
#puts "#{a} for #{len}"
|
||||||
a
|
a
|
||||||
end
|
end
|
||||||
@ -15,7 +15,7 @@ module Padding
|
|||||||
end
|
end
|
||||||
|
|
||||||
def padding_for length
|
def padding_for length
|
||||||
pad = padded(length) - length - 8 # for header, type and layout
|
pad = padded(length) - length - 4 # for header, layout
|
||||||
pad
|
pad
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -10,17 +10,17 @@ class TestPadding < MiniTest::Test
|
|||||||
@pad = Padded.new
|
@pad = Padded.new
|
||||||
end
|
end
|
||||||
def test_small
|
def test_small
|
||||||
[6,20,23,24].each do |p|
|
[6,20,27,28].each do |p|
|
||||||
assert_equal 32 , @pad.padded(p) , "Expecting 32 for #{p}"
|
assert_equal 32 , @pad.padded(p) , "Expecting 32 for #{p}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def test_medium
|
def test_medium
|
||||||
[26,40,53,56].each do |p|
|
[29,40,57,60].each do |p|
|
||||||
assert_equal 64 , @pad.padded(p) , "Expecting 64 for #{p}"
|
assert_equal 64 , @pad.padded(p) , "Expecting 64 for #{p}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def test_large
|
def test_large
|
||||||
[58,88].each do |p|
|
[61,88].each do |p|
|
||||||
assert_equal 96 , @pad.padded(p) , "Expecting 96 for #{p}"
|
assert_equal 96 , @pad.padded(p) , "Expecting 96 for #{p}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user