Skip to content

Commit

Permalink
refactor: reserve wrappedLinesNumbers and replace to emplace if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanAizek committed Aug 13, 2024
1 parent edc7582 commit f097f2c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 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
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/highlighterset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ HighlighterMatchType HighlighterSet::matchLine( const QString& line,
matchType = HighlighterMatchType::WordMatch;
}

matches.insert( matches.end(), std::make_move_iterator( thisMatches.begin() ),
matches.emplace( matches.end(), std::make_move_iterator( thisMatches.begin() ),
std::make_move_iterator( thisMatches.end() ) );
}
}
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
2 changes: 1 addition & 1 deletion src/ui/src/selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ Selection::getSelectionWithLineNumbers( const AbstractLogData* logData ) const

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

Expand Down

0 comments on commit f097f2c

Please sign in to comment.