Skip to content

Commit

Permalink
Don't redo encoding detection on partial index (variar#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
variar committed Nov 12, 2019
1 parent a1fb8d7 commit 98f7583
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
16 changes: 8 additions & 8 deletions src/logdata/include/data/logdataworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ class IndexingData {

struct IndexingState {
EncodingParameters encodingParams;
LineOffset::UnderlyingType pos;
LineLength::UnderlyingType max_length;
LineLength::UnderlyingType additional_spaces;
LineOffset::UnderlyingType end;
LineOffset::UnderlyingType file_size;

QTextCodec* encodingGuess;
QTextCodec* fileTextCodec;
LineOffset::UnderlyingType pos = {};
LineLength::UnderlyingType max_length = {};
LineLength::UnderlyingType additional_spaces = {};
LineOffset::UnderlyingType end = {};
LineOffset::UnderlyingType file_size = {};

QTextCodec* encodingGuess = nullptr;
QTextCodec* fileTextCodec = nullptr;

QSemaphore indexingSem;
QSemaphore blockSem;
Expand Down
29 changes: 18 additions & 11 deletions src/logdata/src/logdataworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,26 @@ FastLinePositionArray IndexOperation::parseDataBlock( LineOffset::UnderlyingType

void IndexOperation::guessEncoding( const QByteArray& block, IndexingState& state ) const
{
if ( !state.encodingGuess ) {
state.encodingGuess = EncodingDetector::getInstance().detectEncoding( block );
LOG( logINFO ) << "Encoding guess " << state.encodingGuess->name().toStdString();
}

if ( !state.fileTextCodec ) {
state.fileTextCodec = indexing_data_.getForcedEncoding();

if ( !state.fileTextCodec ) {
state.fileTextCodec = EncodingDetector::getInstance().detectEncoding( block );
state.fileTextCodec = indexing_data_.getEncodingGuess();
}

if ( !state.fileTextCodec ) {
state.fileTextCodec = state.encodingGuess;
}

state.encodingParams = EncodingParameters( state.fileTextCodec );
LOG( logINFO ) << "Encoding " << state.fileTextCodec->name().toStdString()
<< ", Char width " << state.encodingParams.lineFeedWidth;
}

if ( !state.encodingGuess ) {
state.encodingGuess = EncodingDetector::getInstance().detectEncoding( block );
LOG( logINFO ) << "Encoding guess " << state.encodingGuess->name().toStdString();
}
}

auto IndexOperation::setupIndexingProcess( IndexingState& indexingState )
Expand Down Expand Up @@ -441,13 +446,15 @@ void IndexOperation::doIndex( LineOffset initialPosition )

IndexingState state;
state.pos = initialPosition.get();
state.end = 0ll;
state.additional_spaces = 0;
state.max_length = 0;
state.encodingGuess = nullptr;
state.fileTextCodec = nullptr;
state.file_size = file.size();

state.fileTextCodec = indexing_data_.getForcedEncoding();
if ( !state.fileTextCodec ) {
state.fileTextCodec = indexing_data_.getEncodingGuess();
}

state.encodingGuess = indexing_data_.getEncodingGuess();

auto process = setupIndexingProcess( state );
auto blockSender = std::get<0>( process );

Expand Down

0 comments on commit 98f7583

Please sign in to comment.