Skip to content

refactor: reserve wrappedLinesNumbers and replace to emplace if possible #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ui/include/predefinedfilterscombobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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
2 changes: 2 additions & 0 deletions src/ui/src/abstractlogview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2575,6 +2575,8 @@ void AbstractLogView::drawTextArea( QPaintDevice* paintDevice )
painter->drawText( lineNumberAreaStartX + LineNumberPadding, yPos + fontAscent,
lineNumberStr );
}

wrappedLinesInfo_.reserve(wrappedLinesInfo_.size() + wrappedLineView.wrappedLinesCount());
for ( size_t i = 0u; i < wrappedLineView.wrappedLinesCount(); ++i ) {
wrappedLinesInfo_.emplace_back( WrappedLineData{ lineNumber, i, wrappedLineView } );
}
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 @@ -119,7 +119,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
Loading