Revert "the last headword in the block has incorrect data length"

This reverts commit b617323bfc.
This commit is contained in:
Xiao YiFang 2022-08-07 11:03:46 +08:00
parent efcf033f7e
commit e7f60a9335
3 changed files with 9 additions and 31 deletions

View file

@ -595,12 +595,10 @@ MdictParser::HeadWordIndex MdictParser::splitHeadWordBlock( QByteArray const & b
}
bool MdictParser::readRecordBlock( MdictParser::HeadWordIndex & headWordIndex,
MdictParser::RecordHandler & recordHandler,
bool cross_block_read )
MdictParser::RecordHandler & recordHandler )
{
// cache the index, the headWordIndex is already sorted
size_t idx = 0;
bool readNextBlock = false;
for ( HeadWordIndex::const_iterator i = headWordIndex.begin(); i != headWordIndex.end(); ++i )
{
@ -613,41 +611,21 @@ bool MdictParser::readRecordBlock( MdictParser::HeadWordIndex & headWordIndex,
RecordIndex const & recordIndex = recordBlockInfos_[idx];
HeadWordIndex::const_iterator iNext = i + 1;
qint64 recordSize;
auto current = *i;
if( iNext == headWordIndex.end() )
{
qint64 lastWordSize = recordIndex.shadowEndPos - current.first;
readNextBlock = cross_block_read && readNextHeadWordIndex( headWordIndex );
if(readNextBlock)
{
recordSize = qMin(lastWordSize, headWordIndex.begin()->first - current.first);
}
else
{
recordSize = lastWordSize;
}
}
if ( iNext == headWordIndex.end() )
recordSize = recordIndex.shadowEndPos - i->first;
else
recordSize = iNext->first - current.first;
recordSize = iNext->first - i->first;
RecordInfo recordInfo;
recordInfo.compressedBlockPos = recordPos_ + recordIndex.startPos;
recordInfo.recordOffset = current.first - recordIndex.shadowStartPos;
recordInfo.recordOffset = i->first - recordIndex.shadowStartPos;
recordInfo.decompressedBlockSize = recordIndex.decompressedSize;
recordInfo.compressedBlockSize = recordIndex.compressedSize;
recordInfo.recordSize = recordSize;
recordHandler.handleRecord( current.second, recordInfo );
if( readNextBlock )
break;
recordHandler.handleRecord( i->second, recordInfo );
}
if( readNextBlock )
readRecordBlock( headWordIndex, recordHandler, cross_block_read );
return true;
}

View file

@ -158,7 +158,7 @@ public:
bool open( const char * filename );
bool readNextHeadWordIndex( HeadWordIndex & headWordIndex );
bool readRecordBlock( HeadWordIndex & headWordIndex, RecordHandler & recordHandler, bool cross_block_read=false );
bool readRecordBlock( HeadWordIndex & headWordIndex, RecordHandler & recordHandler );
// helpers
static QString toUtf16( const char * fromCode, const char * from, size_t fromSize );

4
mdx.cc
View file

@ -1440,9 +1440,9 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
MdictParser::HeadWordIndex headWordIndex;
// enumerating word and its definition
if ( parser.readNextHeadWordIndex( headWordIndex ) )
while ( parser.readNextHeadWordIndex( headWordIndex ) )
{
parser.readRecordBlock( headWordIndex, articleHandler, true);
parser.readRecordBlock( headWordIndex, articleHandler );
}
// enumerating resources if there's any