tonellotto / jdbm2

Automatically exported from code.google.com/p/jdbm2
0 stars 0 forks source link

[Enhancement] RecordFile.read() implementation doesn't make sense #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The outer loop (while (remaining > 0)) doesn't make sense since the decrements 
at the end are wrong anyway; it just works if the whole block is read on the 
first file.read(b). This outer loop appears to be a leftover from the original 
JDBM implementation.

Besides, there's no need to pass in the nBytes parameter; the RecordFile class 
creates BlockIos always with an array of BLOCK_SIZE bytes, and thus the 
RecordFile class can rely on this fact and just use buffer.length.

Attached is a rewritten RecordFile.read(). Use or don't use as you like; if you 
do, also omit the last parameter in the call.

(Although I didn't do any serious performance testing, it appears that this 
change does speed up running all the Junit tests by a few percent.)

Original issue reported on code.google.com by t.wolf...@gmail.com on 8 Jun 2011 at 11:42

Attachments:

GoogleCodeExporter commented 9 years ago
This part was reworked, now it uses RandomAccessFile

Original comment by kja...@gmail.com on 12 Jul 2011 at 6:47