From 592a924881fe0061a03ea0b4e90c55350912e595 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Thu, 22 Nov 2012 11:43:52 -0500 Subject: [PATCH] libsaria: Change the path_list to a vector For easier lookups. Signed-off-by: Bryan Schumaker --- libsaria/library/library.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/libsaria/library/library.cpp b/libsaria/library/library.cpp index e5b3154e..76932054 100644 --- a/libsaria/library/library.cpp +++ b/libsaria/library/library.cpp @@ -11,12 +11,12 @@ #include #include "library.h" -#include #include +#include using namespace std; static unsigned int next_id = 0; -static list path_list; +static vector path_list; libsaria::Playlist lib_playlist(PL_STATIC | PL_NO_DRAIN | PL_SORTED); libsaria::library::Path *push_path(libsaria::library::Path &path) @@ -69,11 +69,10 @@ static bool check_trackid(libsaria::Track &track, void *data) void pop_path(libsaria::library::Path *path) { - list::iterator it; - for (it = path_list.begin(); it != path_list.end(); it++) { - if ((*it).id == path->id) { + for (unsigned int i = 0; i < path_list.size(); i++) { + if (&path_list[i] == path) { libsaria::notify(PATH_DELETED, path); - path_list.erase(it); + path_list.erase(path_list.begin() + i); return; } } @@ -122,9 +121,8 @@ namespace libsaria void library::update_all() { - list::iterator it; - for (it = path_list.begin(); it != path_list.end(); it++) - do_update_path(&(*it)); + for (unsigned int i = 0; i < path_list.size(); i++) + do_update_path(&path_list[i]); } void library::hide_path(Path *path) @@ -150,17 +148,12 @@ namespace libsaria Track *library::lookup(unsigned int libid, unsigned int trackid) { - list::iterator p_it; ListItem *track; - for (p_it = path_list.begin(); p_it != path_list.end(); p_it++) { - if (p_it->id == libid) - break; - } - if (p_it == path_list.end()) + if (libid >= path_list.size()) return NULL; - track = p_it->tracks.find_item(check_trackid, &trackid); + track = path_list[libid].tracks.find_item(check_trackid, &trackid); if (track == NULL) return NULL; return &track->get_value();