Class: Ole::Storage::AllocationTable::Big

Inherits:
Ole::Storage::AllocationTable show all
Defined in:
lib/ole/storage/base.rb

Constant Summary

Constants inherited from Ole::Storage::AllocationTable

AVAIL, BAT, EOC, META_BAT

Instance Attribute Summary

Attributes inherited from Ole::Storage::AllocationTable

#block_size, #io, #ole

Instance Method Summary collapse

Methods inherited from Ole::Storage::AllocationTable

#[]=, #chain, #free_block, #load, #open, #ranges, #read, #resize_chain, #to_s, #truncate, #truncate!

Constructor Details

#initialize(*args) ⇒ Big

Returns a new instance of Big.



566
567
568
569
570
# File 'lib/ole/storage/base.rb', line 566

def initialize(*args)
	super
	@block_size = 1 << @ole.header.b_shift
	@io = @ole.io
end

Instance Method Details

#blocks_to_ranges(chain, size = nil) ⇒ Object

Big blocks are kind of -1 based, in order to not clash with the header.



573
574
575
576
577
578
579
580
581
# File 'lib/ole/storage/base.rb', line 573

def blocks_to_ranges chain, size=nil
	#super chain.map { |b| b + 1 }, size
	# duplicated from AllocationTable#blocks_to_ranges to avoid chain.map
	# which was decent part of benchmark profile
	chain = chain[0, (size.to_f / block_size).ceil] if size
	ranges = chain.map { |i| [block_size * (i + 1), block_size] }
	ranges.last[1] -= (ranges.length * block_size - size) if ranges.last and size
	ranges
end