diff --git a/src/Views/ListView/listView.cpp b/src/Views/ListView/listView.cpp index 4dc563f..d992a8d 100644 --- a/src/Views/ListView/listView.cpp +++ b/src/Views/ListView/listView.cpp @@ -89,7 +89,7 @@ ListView::ListView(std::vector homebrews) log_printf(DBG_DEBUG, "posY: %d", posY); log_printf(DBG_DEBUG, "homebrews size: %d", homebrews.size()); this->homebrews = homebrews; - listItems = std::vector(homebrews.size(), nullptr); + listItems = std::vector>(homebrews.size()); LoadListItems(); } @@ -100,7 +100,7 @@ long ListView::_LoadPreviousListItems(long firstDisplayed, long firstToLoad, lon { if (!listItems[i]) { - listItems[i] = new ListItem(homebrews[i]); + listItems[i] = std::make_unique(homebrews[i]); if (++loaded > maxLoad) { break; @@ -117,7 +117,7 @@ long ListView::_LoadShownListItems(long firstDisplayed, long lastDisplayed, long { if (!listItems[i]) { - listItems[i] = new ListItem(homebrews[i]); + listItems[i] = std::make_unique(homebrews[i]); if (++loaded > maxLoad) { break; @@ -134,7 +134,7 @@ long ListView::_LoadNextListItems(long lastDisplayed, long lastToLoad, long maxL { if (!listItems[i]) { - listItems[i] = new ListItem(homebrews[i]); + listItems[i] = std::make_unique(homebrews[i]); if (++loaded > maxLoad) { break; @@ -153,19 +153,11 @@ void ListView::LoadListItems() long loaded = 0; for (long i = 0; i < firstToLoad; i++) { - if (listItems[i]) - { - delete listItems[i]; - listItems[i] = nullptr; - } + listItems[i] = nullptr; } for (long i = lastToLoad; i < (long)listItems.size(); i++) { - if (listItems[i]) - { - delete listItems[i]; - listItems[i] = nullptr; - } + listItems[i] = nullptr; } loaded += _LoadShownListItems(first, last, MAX_LOAD_LIST_ITEMS_PER_CYCLE); diff --git a/src/Views/ListView/listView.h b/src/Views/ListView/listView.h index 23f65d8..eede688 100644 --- a/src/Views/ListView/listView.h +++ b/src/Views/ListView/listView.h @@ -30,7 +30,7 @@ class ListView: public View { protected: std::vector homebrews; - std::vector listItems; + std::vector> listItems; void LoadListItems(); private: diff --git a/src/Views/ListView/searchView.cpp b/src/Views/ListView/searchView.cpp index 952e7b7..2da590b 100644 --- a/src/Views/ListView/searchView.cpp +++ b/src/Views/ListView/searchView.cpp @@ -35,11 +35,8 @@ int SearchView::Display() std::vector hbs; hbs = db->Search(SearchQuery(_ime_search_view_result->userText)); homebrews = hbs; - for (ListItem* item: listItems) { - delete item; - } - listItems.clear(); - listItems = std::vector(homebrews.size(), nullptr); + + std::fill(listItems.begin(), listItems.end(), nullptr); LoadListItems(); lastQuery = _ime_search_view_result->userText; }