List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:June 7 2011 4:35pm
Subject:bzr commit into mysql-trunk branch (alexander.nozdrin:3171)
View as plain text  
#At file:///home/alik/MySQL/bzr/00/bug55843/mysql-trunk-bug55843-01/ based on revid:alexander.nozdrin@stripped

 3171 Alexander Nozdrin	2011-06-07
      General improvements in sql_list.h:
        - reduce copy & paste
        - introduce push_front(void *, MEM_ROOT *)

    modified:
      sql/sql_list.h
=== modified file 'sql/sql_list.h'
--- a/sql/sql_list.h	2011-05-26 15:20:09 +0000
+++ b/sql/sql_list.h	2011-06-07 16:35:40 +0000
@@ -197,36 +197,19 @@ public:
   inline base_list(bool error) { }
   inline bool push_back(void *info)
   {
-    if (((*last)=new list_node(info, &end_of_list)))
-    {
-      last= &(*last)->next;
-      elements++;
-      return 0;
-    }
-    return 1;
+    return push_back_impl(new list_node(info, &end_of_list));
   }
   inline bool push_back(void *info, MEM_ROOT *mem_root)
   {
-    if (((*last)=new (mem_root) list_node(info, &end_of_list)))
-    {
-      last= &(*last)->next;
-      elements++;
-      return 0;
-    }
-    return 1;
+    return push_back_impl(new (mem_root) list_node(info, &end_of_list));
   }
   inline bool push_front(void *info)
   {
-    list_node *node=new list_node(info,first);
-    if (node)
-    {
-      if (last == &first)
-	last= &node->next;
-      first=node;
-      elements++;
-      return 0;
-    }
-    return 1;
+    return push_front_impl(new list_node(info,first));
+  }
+  inline bool push_front(void *info, MEM_ROOT *mem_root)
+  {
+    return push_front_impl(new (mem_root) list_node(info,first));
   }
   void remove(list_node **prev)
   {
@@ -356,6 +339,30 @@ protected:
     if (last == &(node->next))
       last= &new_node->next;
   }
+
+private:
+  inline bool push_front_impl(list_node *node)
+  {
+    if (!node)
+      return true;
+
+    if (last == &first)
+      last= &node->next;
+    first=node;
+    elements++;
+    return false;
+  }
+
+  inline bool push_back_impl(list_node *node)
+  {
+    if (!node)
+      return true;
+
+    *last= node;
+    last= &(*last)->next;
+    elements++;
+    return false;
+  }
 };
 
 
@@ -459,6 +466,8 @@ public:
   inline bool push_back(T *a, MEM_ROOT *mem_root)
   { return base_list::push_back(a, mem_root); }
   inline bool push_front(T *a) { return base_list::push_front(a); }
+  inline bool push_front(T *a, MEM_ROOT *mem_root)
+  { return base_list::push_front(a, mem_root); }
   inline T* head() {return (T*) base_list::head(); }
   inline T** head_ref() {return (T**) base_list::head_ref(); }
   inline T* pop()  {return (T*) base_list::pop(); }


Attachment: [text/bzr-bundle] bzr/alexander.nozdrin@oracle.com-20110607163540-vk1kpvnmz1ttrpim.bundle
Thread
bzr commit into mysql-trunk branch (alexander.nozdrin:3171) Alexander Nozdrin7 Jun