MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sql_list.cc
1 /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
16 
17 #include "unireg.h"
18 #include "sql_list.h"
19 
20 list_node end_of_list;
21 
22 void free_list(I_List <i_string_pair> *list)
23 {
24  i_string_pair *tmp;
25  while ((tmp= list->get()))
26  delete tmp;
27 }
28 
29 
30 void free_list(I_List <i_string> *list)
31 {
32  i_string *tmp;
33  while ((tmp= list->get()))
34  delete tmp;
35 }
36 
37 
38 base_list::base_list(const base_list &rhs, MEM_ROOT *mem_root)
39 {
40  if (rhs.elements)
41  {
42  /*
43  It's okay to allocate an array of nodes at once: we never
44  call a destructor for list_node objects anyway.
45  */
46  first= (list_node*) alloc_root(mem_root,
47  sizeof(list_node) * rhs.elements);
48  if (first)
49  {
50  elements= rhs.elements;
51  list_node *dst= first;
52  list_node *src= rhs.first;
53  for (; dst < first + elements - 1; dst++, src= src->next)
54  {
55  dst->info= src->info;
56  dst->next= dst + 1;
57  }
58  /* Copy the last node */
59  dst->info= src->info;
60  dst->next= &end_of_list;
61  /* Setup 'last' member */
62  last= &dst->next;
63  return;
64  }
65  }
66  elements= 0;
67  first= &end_of_list;
68  last= &first;
69 }