mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
auto file unmap
This commit is contained in:
parent
947323854a
commit
2da252539a
|
@ -5,6 +5,7 @@
|
|||
#include <zlib.h>
|
||||
#include <string.h>
|
||||
#include <QDataStream>
|
||||
#include <QScopeGuard>
|
||||
|
||||
namespace ChunkedStorage {
|
||||
|
||||
|
@ -144,7 +145,6 @@ char * Reader::getBlock( uint32_t address, vector< char > & chunk )
|
|||
|
||||
uint32_t uncompressedSize;
|
||||
uint32_t compressedSize;
|
||||
// = file.read< uint32_t >();
|
||||
|
||||
in >> uncompressedSize >> compressedSize;
|
||||
|
||||
|
@ -155,17 +155,20 @@ char * Reader::getBlock( uint32_t address, vector< char > & chunk )
|
|||
auto chunkDataBytes = file.map( offsets[ chunkIdx ] + 8, compressedSize );
|
||||
|
||||
// file.read( &compressedData.front(), compressedData.size() );
|
||||
auto autoUnmap = qScopeGuard(
|
||||
[ & ] {
|
||||
file.unmap( chunkDataBytes );
|
||||
} );
|
||||
Q_UNUSED( autoUnmap )
|
||||
|
||||
unsigned long decompressedLength = chunk.size();
|
||||
|
||||
if( uncompress( (unsigned char *)&chunk.front(), &decompressedLength, chunkDataBytes, compressedSize ) != Z_OK
|
||||
|| decompressedLength != chunk.size() )
|
||||
{
|
||||
file.unmap( chunkDataBytes );
|
||||
throw exFailedToDecompressChunk();
|
||||
}
|
||||
|
||||
file.unmap( chunkDataBytes );
|
||||
}
|
||||
|
||||
size_t offsetInChunk = address & 0xffFF;
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "wildcard.hh"
|
||||
#include <QtConcurrent>
|
||||
#include "base/globalregex.hh"
|
||||
#include <QFutureSynchronizer>
|
||||
#include <QSemaphoreReleaser>
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
|
Loading…
Reference in a new issue