Skip to content

Commit

Permalink
Use structure for raw lines
Browse files Browse the repository at this point in the history
  • Loading branch information
variar committed Apr 20, 2021
1 parent 3b65843 commit e921e72
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
9 changes: 8 additions & 1 deletion src/logdata/include/data/logdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ class LogData : public AbstractLogData {
// Get the auto-detected encoding for the indexed text.
QTextCodec* getDetectedEncoding() const;

using RawLines = std::tuple<LineNumber, LinesCount, std::vector<char>, std::vector<qint64>>;
struct RawLines
{
LineNumber startLine;
LinesCount numberOfLines;
std::vector<char> buffer;
std::vector<qint64> endOfLines;
};

RawLines getLinesRaw(LineNumber first, LinesCount number) const;
std::vector<QString> decodeLines(const RawLines& rawLines) const;

Expand Down
25 changes: 9 additions & 16 deletions src/logdata/src/logdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,35 +364,28 @@ LogData::RawLines LogData::getLinesRaw( LineNumber first_line, LinesCount number

LOG_DEBUG << "LogData::getLines done reading lines:" << buffer.size();

return std::make_tuple( first_line, number, std::move( buffer ), std::move( endOfLines ) );
return { first_line, number, std::move( buffer ), std::move( endOfLines ) };
}

std::vector<QString> LogData::decodeLines( const RawLines& rawLines ) const
{

LineNumber first_line = std::get<0>(rawLines);
LinesCount number = std::get<1>(rawLines);
const std::vector<char>& buffer = std::get<2>(rawLines);
const std::vector<qint64>& endOfLines = std::get<3>(rawLines);

//std::tie( first_line, number, buffer, endOfLines ) = rawLines;

if ( number.get() == 0 ) {
if ( rawLines.numberOfLines.get() == 0 ) {
return std::vector<QString>();
}

std::vector<QString> decodedLines;
decodedLines.reserve( number.get() );
decodedLines.reserve( rawLines.numberOfLines.get() );

const auto last_line = first_line + number - 1_lcount;
const auto lastLine = rawLines.startLine + rawLines.numberOfLines - 1_lcount;

qint64 lineStart = 0;
size_t currentLine = 0;
auto decoder = codec_.makeDecoder();
const auto lineFeedWidth = decoder.second.lineFeedWidth;

for ( LineNumber line = first_line; ( line <= last_line ); ++line, ++currentLine ) {
const auto lineEnd = endOfLines[ currentLine ];
for ( LineNumber line = rawLines.startLine; ( line <= lastLine ); ++line, ++currentLine ) {
const auto lineEnd = rawLines.endOfLines[ currentLine ];

const auto length = lineEnd - lineStart - lineFeedWidth;

Expand All @@ -403,19 +396,19 @@ std::vector<QString> LogData::decodeLines( const RawLines& rawLines ) const
break;
}

if ( lineStart + length > static_cast<qint64>( buffer.size() ) ) {
if ( lineStart + length > static_cast<qint64>( rawLines.buffer.size() ) ) {
decodedLines.emplace_back( "KLOGG WARNING: file read failed" );
LOG_WARNING << "LogData::getLines not enough data in buffer";
break;
}

decodedLines.push_back(
decoder.first->toUnicode( buffer.data() + lineStart, static_cast<int>( length ) ) );
decoder.first->toUnicode( rawLines.buffer.data() + lineStart, static_cast<int>( length ) ) );

lineStart = lineEnd;
}

while ( decodedLines.size() < number.get() ) {
while ( decodedLines.size() < rawLines.numberOfLines.get() ) {
decodedLines.emplace_back( "KLOGG WARNING: failed to read some lines before this one" );
}

Expand Down
14 changes: 6 additions & 8 deletions src/logdata/src/logfiltereddataworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,16 @@ PartialSearchResults filterLines( const MatcherVariant& matcher, const std::vect
PartialSearchResults results;
results.chunkStart = chunkStart;
results.processedLines = LinesCount( static_cast<LinesCount::UnderlyingType>( lines.size() ) );
for ( size_t i = 0; i < lines.size(); ++i ) {
const auto& l = lines.at( i );
for ( auto offset = 0_lcount; offset < results.processedLines; ++offset ) {
const auto& line = lines[ offset.get() ];

const auto hasMatch
= absl::visit( [&l]( const auto& m ) { return m.hasMatch( l ); }, matcher );
= absl::visit( [&line]( const auto& m ) { return m.hasMatch( line ); }, matcher );

if ( hasMatch ) {
results.maxLength = qMax( results.maxLength, getUntabifiedLength( l ) );
results.matchingLines
= std::move( results.matchingLines )
.push_back( chunkStart
+ LinesCount( static_cast<LinesCount::UnderlyingType>( i ) ) );
results.maxLength = qMax( results.maxLength, getUntabifiedLength( line ) );
const auto lineNumber = chunkStart + offset;
results.matchingLines = std::move( results.matchingLines ).push_back( lineNumber );
}
}
return results;
Expand Down
4 changes: 0 additions & 4 deletions src/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,5 @@ target_link_libraries(utils PUBLIC
whereami
plog)

if(KLOGG_USE_HYPERSCAN)
target_compile_definitions(utils PUBLIC KLOGG_HAS_HS)
endif()

add_dependencies(utils generate_version)

0 comments on commit e921e72

Please sign in to comment.