Skip to content

Commit

Permalink
refactor: optimize selection data structures, reserve selectionData a…
Browse files Browse the repository at this point in the history
…nd wrappedLinesNumbers
  • Loading branch information
GermanAizek committed Aug 28, 2024
1 parent edc7582 commit e572e08
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/ui/include/predefinedfilterscombobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PredefinedFiltersComboBox final : public QComboBox {
PredefinedFiltersComboBox& operator=( PredefinedFiltersComboBox&& other ) = delete;

void populatePredefinedFilters();
void updateSearchPattern( const QString newSearchPattern, bool useLogicalCombining );
void updateSearchPattern( const QString& newSearchPattern, bool useLogicalCombining );

virtual void showPopup();

Expand Down
2 changes: 1 addition & 1 deletion src/ui/include/selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Selection {
FilePosition getPreviousPosition() const;

private:
std::map<LineNumber, QString>
std::vector<std::pair<LineNumber, QString>>
getSelectionWithLineNumbers( const AbstractLogData* logData ) const;

private:
Expand Down
11 changes: 6 additions & 5 deletions src/ui/src/abstractlogview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class WrappedLinesView {
explicit WrappedLinesView( const QString& longLine, LineLength visibleColumns )
{
if ( longLine.isEmpty() ) {
wrappedLines_.push_back( WrappedString{} );
wrappedLines_.emplace_back( );
}
else {
#if QT_VERSION >= QT_VERSION_CHECK( 5, 10, 0 )
Expand Down Expand Up @@ -264,7 +264,7 @@ class WrappedLinesView {
if ( wrappedLines_.size() == 1 ) {
auto& wrappedLine = wrappedLines_.front();
auto len = std::min( length.get(), getLength( wrappedLine ) - start.get() );
resultChunks.push_back( wrappedLine.mid( start.get(), ( len > 0 ? len : 0 ) ) );
resultChunks.emplace_back( wrappedLine.mid( start.get(), ( len > 0 ? len : 0 ) ) );
return resultChunks;
}

Expand All @@ -281,7 +281,7 @@ class WrappedLinesView {
auto chunkLength = length.get();
while ( positionInWrappedLine + chunkLength
> getLength( wrappedLines_[ wrappedLineIndex ] ) ) {
resultChunks.push_back(
resultChunks.emplace_back(
wrappedLines_[ wrappedLineIndex ].mid( positionInWrappedLine ) );
wrappedLineIndex++;
positionInWrappedLine = 0;
Expand All @@ -294,7 +294,7 @@ class WrappedLinesView {
if ( chunkLength > 0 ) {
auto& wrappedLine = wrappedLines_[ wrappedLineIndex ];
auto len = std::min( chunkLength, getLength( wrappedLine ) - positionInWrappedLine );
resultChunks.push_back(
resultChunks.emplace_back(
wrappedLine.mid( positionInWrappedLine, ( len > 0 ? len : 0 ) ) );
}

Expand Down Expand Up @@ -2668,8 +2668,9 @@ void AbstractLogView::drawTextArea( QPaintDevice* paintDevice )
painter->drawText( lineNumberAreaStartX + LineNumberPadding, yPos + fontAscent,
lineNumberStr );
}
wrappedLinesNumbers_.reserve(wrappedLineView.wrappedLinesCount());
for ( auto i = 0u; i < wrappedLineView.wrappedLinesCount(); ++i ) {
wrappedLinesNumbers_.push_back( std::make_pair( lineNumber, i ) );
wrappedLinesNumbers_.emplace_back( lineNumber, i );
}

yPos += finalLineHeight;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/src/predefinedfilterscombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void PredefinedFiltersComboBox::populatePredefinedFilters()
this->setModel( model_ );
}

void PredefinedFiltersComboBox::updateSearchPattern( const QString newSearchPattern, bool useLogicalCombining )
void PredefinedFiltersComboBox::updateSearchPattern( const QString& newSearchPattern, bool useLogicalCombining )
{
searchPattern_.newOne_ = newSearchPattern;
searchPattern_.useLogicalCombining_ = useLogicalCombining;
Expand Down
17 changes: 9 additions & 8 deletions src/ui/src/selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,29 +189,30 @@ QString Selection::getSelectedText( const AbstractLogData* logData, bool lineNum
return text;
}

std::map<LineNumber, QString>
std::vector<std::pair<LineNumber, QString>>
Selection::getSelectionWithLineNumbers( const AbstractLogData* logData ) const
{
std::map<LineNumber, QString> selectionData;
std::vector<std::pair<LineNumber, QString>> selectionData;

if ( selectedLine_.has_value() ) {
selectionData.emplace( logData->getLineNumber( selectedLine_.value() ),
selectionData.emplace_back( logData->getLineNumber( selectedLine_.value() ),
logData->getLineString( *selectedLine_ ) );
}
else if ( selectedPartial_.line.has_value() ) {
selectionData.emplace(
selectionData.emplace_back(
logData->getLineNumber( selectedPartial_.line.value() ),
logData->getExpandedLineString( *selectedPartial_.line )
.mid( selectedPartial_.startColumn.get(),
selectedPartial_.size().get() ) );
}
else if ( selectedRange_.startLine.has_value() ) {
const auto list = logData->getLines( *selectedRange_.startLine, selectedRange_.size() );
LineNumber ln = *selectedRange_.startLine;
const auto list = logData->getLines( selectedRange_.startLine.value(), selectedRange_.size() );
LineNumber ln = selectedRange_.startLine.value();

selectionData.reserve(list.size());
for ( const auto& line : list ) {
selectionData.emplace( logData->getLineNumber( ln ), line );
ln++;
selectionData.emplace_back( logData->getLineNumber( ln ), line );
++ln;
}
}

Expand Down

0 comments on commit e572e08

Please sign in to comment.