Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=56347b8df4a884099c49839a449d7aeeeedae18b
commit 56347b8df4a884099c49839a449d7aeeeedae18b Author: Michel Hermier <[email protected]> Date: Mon Sep 8 18:29:13 2014 +0200 libpacman: Make FPtrList a ring list. diff --git a/lib/libpacman/conflict.cpp b/lib/libpacman/conflict.cpp index 15eb7e4..97fe9f6 100644 --- a/lib/libpacman/conflict.cpp +++ b/lib/libpacman/conflict.cpp @@ -203,7 +203,7 @@ static FStringList chk_fileconflicts(const FStringList &filesA, const FStringLis FStringList ret; auto pA = filesA.begin(), pB = filesB.begin(); - while(pA && pB) { + while(pA != filesA.end() && pB != filesB.end()) { const char *strA = f_stringlistitem_to_str(pA); const char *strB = f_stringlistitem_to_str(pB); /* skip directories, we don't care about dir conflicts */ diff --git a/lib/libpacman/deps.cpp b/lib/libpacman/deps.cpp index a8ce1f0..5229d24 100644 --- a/lib/libpacman/deps.cpp +++ b/lib/libpacman/deps.cpp @@ -46,6 +46,10 @@ using namespace libpacman; typedef struct __pmgraph_t { + __pmgraph_t() + : state(0), data(nullptr), parent(nullptr), childptr(nullptr) + { } + int state; /* 0: untouched, -1: entered, other: leaving time */ Package *data; struct __pmgraph_t *parent; /* where did we come from? */ @@ -55,9 +59,7 @@ typedef struct __pmgraph_t { static pmgraph_t *_pacman_graph_new(void) { - pmgraph_t *graph = (pmgraph_t *)_pacman_zalloc(sizeof(pmgraph_t)); - - return(graph); + return new pmgraph_t(); } __pmdepmissing_t::__pmdepmissing_t(const char *target, unsigned char type, unsigned char depmod, @@ -116,7 +118,6 @@ FPtrList _pacman_sortbydeps(const FPtrList &targets, int mode) { FPtrList newtargs; FPtrList vertices; - FPtrListIterator *vptr; pmgraph_t *vertex; int found; @@ -155,13 +156,13 @@ FPtrList _pacman_sortbydeps(const FPtrList &targets, int mode) vertex_i->childptr = vertex_i->children.begin(); } - vptr = vertices.begin(); + FPtrListIterator *vptr = vertices.begin(), *end = vertices.end(); vertex = f_ptrlistitem_data(vptr); - while(vptr) { + while(vptr != end) { /* mark that we touched the vertex */ vertex->state = -1; found = 0; - while(vertex->childptr && !found) { + while(vertex->childptr != vertex->children.end() && !found) { pmgraph_t *nextchild = f_ptrlistitem_data(vertex->childptr); vertex->childptr = vertex->childptr->next(); if (nextchild->state == 0) { @@ -179,7 +180,7 @@ FPtrList _pacman_sortbydeps(const FPtrList &targets, int mode) vertex = vertex->parent; if(!vertex) { vptr = vptr->next(); - while(vptr) { + while(vptr != end) { vertex = f_ptrlistitem_data(vptr); if (vertex->state == 0) break; vptr = vptr->next(); diff --git a/lib/libpacman/util/flist.h b/lib/libpacman/util/flist.h index d4923a2..15cc61e 100644 --- a/lib/libpacman/util/flist.h +++ b/lib/libpacman/util/flist.h @@ -439,6 +439,16 @@ public: return true; } + FCListItem *next() const + { + return m_next; + } + + FCListItem *previous() const + { + return m_previous; + } + protected: FCListItem *m_next; FCListItem *m_previous; diff --git a/lib/libpacman/util/fptrlist.cpp b/lib/libpacman/util/fptrlist.cpp index 88f14bf..0de0955 100644 --- a/lib/libpacman/util/fptrlist.cpp +++ b/lib/libpacman/util/fptrlist.cpp @@ -34,31 +34,18 @@ FPtrList *f_ptrlist_add_sorted(FPtrList *list, void *data, _pacman_fn_cmp fn) list = new FPtrList(); } -#ifndef F_NOCOMPAT - if(list->m_data == NULL) { - list->m_data = data; - } else if(fn(data, list->m_data) <= 0) { - /* Insert before in head */ - FPtrListItem *next = new FPtrListItem(list->m_data); - list->m_data = data; - next->insert_after(list); - } else { -#endif FPtrListIterator *add = new FPtrListItem(data); /* Find insertion point. */ - FPtrListIterator *previous = list; - for(FPtrListIterator *end = f_ptrlist_end(list); previous->next() != end; previous = previous->next()) { - if(fn(f_ptrlistitem_data(add), f_ptrlistitem_data(previous->next())) <= 0) { + FCListItem *previous = list; + for(FCListItem *end = f_ptrlist_end(list); previous->next() != end; previous = previous->next()) { + if(fn(data, f_ptrlistitem_data((FPtrListItem *)previous->next())) <= 0) { break; } } /* Insert node before insertion point. */ add->insert_after(previous); -#ifndef F_NOCOMPAT - } -#endif return list; } @@ -76,33 +63,6 @@ bool _pacman_list_remove(FPtrList *haystack, void *needle, _pacman_fn_cmp fn, vo *data = NULL; } -#ifndef F_NOCOMPAT - if(haystack->empty()) { - return false; - } - - if(fn(needle, haystack->m_data) == 0) { - /* The item found is the first in the chain */ - FPtrListItem *next = haystack->next(); - - if(data != NULL) { - *data = haystack->m_data; - } - if(next == NULL) { - /* Mark list empty */ - haystack->m_data = NULL; - } else { - /* Move data of next item in list head */ - haystack->m_data = next->m_data; - haystack->m_next = next->next(); - if(haystack->m_next) { - haystack->m_next->m_previous = haystack; - } - delete next; - } - return true; - } -#endif for(FPtrListIterator *i = f_ptrlist_first(haystack), *end = f_ptrlist_end(haystack); i != end; i = i->next()) { if(fn(needle, i->m_data) == 0) { /* we found a matching item */ @@ -180,15 +140,7 @@ int f_ptrlist_delete(FPtrList *self, FVisitor *visitor) FPtrList &FPtrList::add(void *data) { -#ifndef F_NOCOMPAT - if(m_data == NULL) { - m_data = (void *)data; - } else { -#endif (new FPtrListItem(data))->insert_after(last()); -#ifndef F_NOCOMPAT - } -#endif return *this; } @@ -207,17 +159,6 @@ int f_ptrlist_clear(FPtrList *list, FVisitor *visitor) FPtrListIterator *end = f_ptrlist_end(list), *it = f_ptrlist_first(list), *next; -#ifndef F_NOCOMPAT - if(list->empty()) { - return 0; - } - - if(visitor != NULL) { - f_visit(f_ptrlistitem_data(it), visitor); - } - it = it->next(); -#endif - while(it != end) { next = it->next(); if(visitor != NULL) { diff --git a/lib/libpacman/util/fptrlist.h b/lib/libpacman/util/fptrlist.h index a9bdee6..332a8e1 100644 --- a/lib/libpacman/util/fptrlist.h +++ b/lib/libpacman/util/fptrlist.h @@ -50,7 +50,7 @@ public: }; class FPtrList - : protected FPtrListItem + : protected FCListItem { public: friend FPtrList *f_ptrlist_add_sorted(FPtrList *list, void *data, _pacman_fn_cmp fn); @@ -61,6 +61,7 @@ public: typedef const iterator const_iterator; FPtrList() + : FCListItem(this, this) { } FPtrList(FPtrList &&o) @@ -78,7 +79,7 @@ public: iterator begin() { ASSERT(this != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL)); - return m_data != NULL ? this : end(); + return iterator(next()); } const_iterator begin() const @@ -89,45 +90,37 @@ public: const_iterator cbegin() const { ASSERT(this != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL)); - return m_data != NULL ? const_cast<const_iterator>((const FPtrListItem * const)this) : NULL; + return const_iterator(next()); } iterator end() { - return NULL; + return iterator(this); } const_iterator end() const { - return NULL; + return cend(); } const_iterator cend() const { - return NULL; + return const_iterator(this); } iterator last() { - return const_cast<iterator>(clast()); + return iterator(previous()); } const_iterator last() const { - auto it = cbegin(), end = cend(); - - if (it != end) - { - while (it->next() != end) { - it = it->next(); - } - } - return it; + return clast(); } const_iterator clast() const { - return last(); + return const_iterator(previous()); } iterator rbegin() @@ -147,23 +140,23 @@ public: iterator rend() { - return NULL; + return iterator(this); } const_iterator rend() const { - return NULL; + return crend(); } const_iterator crend() const { - return NULL; + return const_iterator(this); } bool empty() const { ASSERT(this != NULL, RET_ERR(PM_ERR_WRONG_ARGS, true)); - return this->m_data == NULL; + return begin() == end(); } FPtrList &add(void *data); @@ -172,25 +165,23 @@ public: { // FIXME: lets leak for now ASSERT(this != NULL, pm_errno = PM_ERR_WRONG_ARGS; return); - m_next = m_previous = NULL; - m_data = NULL; + m_next = m_previous = this; } void swap(FPtrList &o) { - std::swap(m_data, o.m_data); std::swap(m_next, o.m_next); std::swap(m_previous, o.m_previous); - if (m_next != NULL) { + if(m_next != &o) { m_next->m_previous = this; - } - if (m_previous != NULL) { m_previous->m_next = this; + } else { + m_next = m_previous = this; } - if (o.m_next != NULL) { + if(o.m_next != this) { o.m_next->m_previous = &o; - } - if (o.m_previous != NULL) { o.m_previous->m_next = &o; + } else { + o.m_next = o.m_previous = &o; } } private: diff --git a/src/pacman-g2/query.c b/src/pacman-g2/query.c index 35944b3..e7232a6 100644 --- a/src/pacman-g2/query.c +++ b/src/pacman-g2/query.c @@ -44,8 +44,7 @@ int querypkg(FStringList *targets) { PM_PKG *info = NULL; PM_LIST *ret; - char *package = NULL; - int done = 0, errors = 0; + int errors = 0; if(config->op_q_search) { for(FPtrListIterator *i = f_ptrlist_first(targets), *end = f_ptrlist_end(targets); i != end; i = f_ptrlistitem_next(i)) { @@ -84,15 +83,8 @@ int querypkg(FStringList *targets) return(1); } - for(FPtrListIterator *targ = f_ptrlist_first(targets); !done; targ = (targ ? f_ptrlistitem_next(targ) : NULL)) { - if(targets == NULL) { - done = 1; - } else { - if(f_ptrlistitem_next(targ) == NULL) { - done = 1; - } - package = list_data(targ); - } + for(FPtrListIterator *targ = f_ptrlist_first(targets), *end = f_ptrlist_end(targets); targ != end; targ = f_ptrlistitem_next(targ)) { + char *package = list_data(targ); /* looking for groups */ if(config->group) { _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
