diff options
author | unknown <serg@serg.mylan> | 2005-05-19 09:50:43 +0200 |
---|---|---|
committer | unknown <serg@serg.mylan> | 2005-05-19 09:50:43 +0200 |
commit | 27378545f9d9265e4dc9bec00e560f717457a8e7 (patch) | |
tree | 289254c82cd6b8396326a209eb82434e4b742715 /sql/sql_list.h | |
parent | 9e8cad1d5a87c681b48266c96f2e1ea98052b40a (diff) | |
parent | 275aa247405e3fbd364598132858b27e9e47cc7d (diff) | |
download | mariadb-git-27378545f9d9265e4dc9bec00e560f717457a8e7.tar.gz |
Merge serg@bk-internal.mysql.com:/home/bk/mysql-4.1/
into serg.mylan:/usr/home/serg/Abk/mysql-4.1
Diffstat (limited to 'sql/sql_list.h')
-rw-r--r-- | sql/sql_list.h | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/sql/sql_list.h b/sql/sql_list.h index 45a6b5066eb..e799ecf3d6e 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -129,10 +129,32 @@ public: void remove(list_node **prev) { list_node *node=(*prev)->next; + if (&(*prev)->next == last) + { + /* + We're removing the last element from the list. Adjust "last" to point + to the previous element. + The other way to fix this would be to change this function to + remove_next() and have base_list_iterator save ptr to previous node + (one extra assignment in iterator++) but as the remove() of the last + element isn't a common operation it's faster to just walk through the + list from the beginning here. + */ + list_node *cur= first; + if (cur == *prev) + { + last= &first; + } + else + { + while (cur->next != *prev) + cur= cur->next; + last= &(cur->next); + } + } delete *prev; *prev=node; - if (!--elements) - last= &first; + elements--; } inline void concat(base_list *list) { @@ -162,6 +184,54 @@ public: friend class error_list; friend class error_list_iterator; +#ifdef LIST_EXTRA_DEBUG + /* + Check list invariants and print results into trace. Invariants are: + - (*last) points to end_of_list + - There are no NULLs in the list. + - base_list::elements is the number of elements in the list. + + SYNOPSIS + check_list() + name Name to print to trace file + + RETURN + 1 The list is Ok. + 0 List invariants are not met. + */ + + bool check_list(const char *name) + { + base_list *list= this; + list_node *node= first; + uint cnt= 0; + + while (node->next != &end_of_list) + { + if (!node->info) + { + DBUG_PRINT("list_invariants",("%s: error: NULL element in the list", + name)); + return FALSE; + } + node= node->next; + cnt++; + } + if (last != &(node->next)) + { + DBUG_PRINT("list_invariants", ("%s: error: wrong last pointer", name)); + return FALSE; + } + if (cnt+1 != elements) + { + DBUG_PRINT("list_invariants", ("%s: error: wrong element count", name)); + return FALSE; + } + DBUG_PRINT("list_invariants", ("%s: list is ok", name)); + return TRUE; + } +#endif // LIST_EXTRA_DEBUG + protected: void after(void *info,list_node *node) { |