From e7f60a9335618d9e95188c98308b2346c1ea177a Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sun, 7 Aug 2022 11:03:46 +0800 Subject: [PATCH] Revert "the last headword in the block has incorrect data length" This reverts commit b617323bfc50aef9f359782b8ad7c4acb92e1c6a. --- mdictparser.cc | 34 ++++++---------------------------- mdictparser.hh | 2 +- mdx.cc | 4 ++-- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/mdictparser.cc b/mdictparser.cc index 7b03b9a6..931a8fff 100644 --- a/mdictparser.cc +++ b/mdictparser.cc @@ -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; } diff --git a/mdictparser.hh b/mdictparser.hh index fc78af6d..bd754f56 100644 --- a/mdictparser.hh +++ b/mdictparser.hh @@ -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 ); diff --git a/mdx.cc b/mdx.cc index 539fc815..f720a3cc 100644 --- a/mdx.cc +++ b/mdx.cc @@ -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