Skip to content

Commit

Permalink
view: insert directly if sorting is not required
Browse files Browse the repository at this point in the history
O(n) -> O(1)
  • Loading branch information
jesec committed May 13, 2022
1 parent 8b9946c commit 0ea14ae
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/core/view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ View::prev_focus() {

void
View::sort() {
if (m_sortCurrent.is_empty()) {
return;
}

Download* curFocus = focus() != end_visible() ? *focus() : nullptr;

// Don't go randomly switching around equivalent elements.
Expand Down Expand Up @@ -371,7 +375,10 @@ View::clear_filter_on() {
inline void
View::insert_visible(Download* d) {
iterator itr =
std::find_if(begin_visible(), end_visible(), [d, this](Download* download) {
m_sortNew.is_empty()
? end_visible()
: std::find_if(
begin_visible(), end_visible(), [d, this](Download* download) {
return view_downloads_compare(m_sortNew)(d, download);
});

Expand Down

0 comments on commit 0ea14ae

Please sign in to comment.