Skip to content

Commit

Permalink
[ci release] Fix crash on last line
Browse files Browse the repository at this point in the history
  • Loading branch information
variar committed May 19, 2021
1 parent 7fddde5 commit b39641f
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 84 deletions.
32 changes: 16 additions & 16 deletions src/logdata/include/data/logdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ class LogData : public AbstractLogData {
LogData();
~LogData();

LogData(const LogData&) = delete;
LogData& operator=(const LogData&&) = delete;
LogData( const LogData& ) = delete;
LogData& operator=( const LogData&& ) = delete;

LogData(LogData&&) = delete;
LogData& operator=(LogData&&) = delete;
LogData( LogData&& ) = delete;
LogData& operator=( LogData&& ) = delete;

// Attaches the LogData to a file on disk
// It starts the asynchronous indexing and returns (almost) immediately
Expand All @@ -100,24 +100,24 @@ class LogData : public AbstractLogData {
// Get the auto-detected encoding for the indexed text.
QTextCodec* getDetectedEncoding() const;

struct RawLines
{
LineNumber startLine;
LinesCount numberOfLines;
struct RawLines {
LineNumber startLine;
LinesCount numberOfLines;

std::vector<char> buffer;
std::vector<qint64> endOfLines;
std::vector<char> buffer;
std::vector<qint64> endOfLines;

TextDecoder textDecoder;
TextDecoder textDecoder;

std::vector<QString> decodeLines() const;
std::vector<std::string_view> transformToUtf8() const;
public:
std::vector<QString> decodeLines() const;
std::vector<std::string_view> buildUtf8View() const;

private:
mutable QByteArray utf8Data_;
mutable QByteArray utf8Data_;
};

RawLines getLinesRaw(LineNumber first, LinesCount number) const;
RawLines getLinesRaw( LineNumber first, LinesCount number ) const;

signals:
// Sent during the 'attach' process to signal progress
Expand Down Expand Up @@ -156,7 +156,7 @@ class LogData : public AbstractLogData {
std::vector<QString> getLinesFromFile( LineNumber first, LinesCount number,
QString ( *processLine )( QString&& ) ) const;

private:
private:
mutable std::unique_ptr<FileHolder> attached_file_;

// Indexing data, read by us, written by the worker thread
Expand Down
8 changes: 6 additions & 2 deletions src/logdata/src/logdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ std::vector<QString> LogData::RawLines::decodeLines() const
return decodedLines;
}

std::vector<std::string_view> LogData::RawLines::transformToUtf8() const
std::vector<std::string_view> LogData::RawLines::buildUtf8View() const
{
std::vector<std::string_view> lines;
lines.reserve( numberOfLines.get() );
Expand All @@ -493,11 +493,15 @@ std::vector<std::string_view> LogData::RawLines::transformToUtf8() const

auto nextLineFeed = wholeString.find( '\n' );
while ( nextLineFeed != std::string_view::npos ) {
lines.emplace_back( wholeString.data(), nextLineFeed );
lines.push_back( wholeString.substr( 0, nextLineFeed ) );
wholeString.remove_prefix( nextLineFeed + 1 );
nextLineFeed = wholeString.find( '\n' );
}

if ( !wholeString.empty() ) {
lines.push_back( wholeString );
}

} catch ( const std::exception& e ) {
LOG_ERROR << "failed to transform lines to utf8 " << e.what();
const auto lastLineOffset = utf8Data_.size();
Expand Down
8 changes: 4 additions & 4 deletions src/logdata/src/logfiltereddataworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ PartialSearchResults filterLines( const MatcherVariant& matcher, const LogData::
results.chunkStart = chunkStart;
results.processedLines = rawLines.numberOfLines;

const auto& lines = rawLines.transformToUtf8();
const auto& lines = rawLines.buildUtf8View();

for ( auto offset = 0_lcount; offset < results.processedLines; ++offset ) {
const auto& line = lines[ offset.get() ];
for ( auto offset = 0u; offset < lines.size(); ++offset ) {
const auto& line = lines[ offset ];

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

if ( hasMatch ) {
results.maxLength = qMax( results.maxLength, getUntabifiedLength( line ) );
const auto lineNumber = chunkStart + offset;
const auto lineNumber = chunkStart + LinesCount{offset};
results.matchingLines.add( lineNumber.get() );

// LOG_INFO << "Match at " << lineNumber << ": " << line;
Expand Down
Loading

0 comments on commit b39641f

Please sign in to comment.