List:Commits« Previous MessageNext Message »
From:Tor Didriksen Date:September 19 2011 9:35am
Subject:bzr push into mysql-trunk branch (tor.didriksen:3437 to 3438)
View as plain text  
 3438 Tor Didriksen	2011-09-19
      Try some simple stl usage in the server.

    modified:
      sql/mysqld.cc
      sql/set_var.cc
      sql/set_var.h
      sql/sql_plugin.cc
      sql/sql_plugin.h
 3437 Tor Didriksen	2011-09-16
      switch off fast mutexes by default

    modified:
      CMakeLists.txt
=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2011-08-30 12:57:45 +0000
+++ b/sql/mysqld.cc	2011-09-19 09:34:39 +0000
@@ -14,6 +14,11 @@
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 #include "my_global.h"                          /* NO_EMBEDDED_ACCESS_CHECKS */
+
+#include <vector>
+#include <algorithm>
+#include <functional>
+
 #include "sql_priv.h"
 #include "unireg.h"
 #include <signal.h>
@@ -96,6 +101,7 @@
 
 using std::min;
 using std::max;
+using std::vector;
 
 #define mysqld_charset &my_charset_latin1
 
@@ -957,7 +963,7 @@ uint connection_count= 0;
 pthread_handler_t signal_hand(void *arg);
 static int mysql_init_variables(void);
 static int get_options(int *argc_ptr, char ***argv_ptr);
-static bool add_terminator(DYNAMIC_ARRAY *options);
+static void add_terminator(vector<my_option> *options);
 extern "C" my_bool mysqld_get_one_option(int, const struct my_option *, char *);
 static void set_server_version(void);
 static int init_thread_environment();
@@ -4667,14 +4673,14 @@ int mysqld_main(int argc, char **argv)
     before to-be-instrumented objects of the server are initialized.
   */
   int ho_error;
-  DYNAMIC_ARRAY all_early_options;
+  vector<my_option> all_early_options;
+  all_early_options.reserve(100);
 
   my_getopt_register_get_addr(NULL);
   /* Skip unknown options so that they may be processed later */
   my_getopt_skip_unknown= TRUE;
 
   /* prepare all_early_options array */
-  my_init_dynamic_array(&all_early_options, sizeof(my_option), 100, 25);
   sys_var_add_options(&all_early_options, sys_var::PARSE_EARLY);
   add_terminator(&all_early_options);
 
@@ -4687,8 +4693,7 @@ int mysqld_main(int argc, char **argv)
   my_charset_error_reporter= buffered_option_error_reporter;
 
   ho_error= handle_options(&remaining_argc, &remaining_argv,
-                           (my_option*)(all_early_options.buffer), NULL);
-  delete_dynamic(&all_early_options);
+                           &all_early_options[0], NULL);
   if (ho_error == 0)
   {
     /* Add back the program name handle_options removes */
@@ -6121,7 +6126,7 @@ error:
   Handle start options
 ******************************************************************************/
 
-DYNAMIC_ARRAY all_options;
+vector<my_option> all_options;
 
 /**
   System variables are automatically command-line options (few
@@ -7154,10 +7159,11 @@ SHOW_VAR status_vars[]= {
   {NullS, NullS, SHOW_LONG}
 };
 
-bool add_terminator(DYNAMIC_ARRAY *options)
+void add_terminator(vector<my_option> *options)
 {
-  my_option empty_element= {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0};
-  return insert_dynamic(options, &empty_element);
+  my_option empty_element=
+    {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0};
+  options->push_back(empty_element);
 }
 
 #ifndef EMBEDDED_LIBRARY
@@ -7170,10 +7176,10 @@ static void print_version(void)
 }
 
 /** Compares two options' names, treats - and _ the same */
-static int option_cmp(my_option *a, my_option *b)
+static bool operator<(const my_option &a, const my_option &b)
 {
-  const char *sa= a->name;
-  const char *sb= b->name;
+  const char *sa= a.name;
+  const char *sb= b.name;
   for (; *sa || *sb; sa++, sb++)
   {
     if (*sa < *sb)
@@ -7181,18 +7187,18 @@ static int option_cmp(my_option *a, my_o
       if (*sa == '-' && *sb == '_')
         continue;
       else
-        return -1;
+        return true;
     }
     if (*sa > *sb)
     {
       if (*sa == '_' && *sb == '-')
         continue;
       else
-        return 1;
+        return false;
     }
   }
-  DBUG_ASSERT(a->name == b->name);
-  return 0;
+  DBUG_ASSERT(a.name == b.name);
+  return false;
 }
 
 static void print_help()
@@ -7200,17 +7206,18 @@ static void print_help()
   MEM_ROOT mem_root;
   init_alloc_root(&mem_root, 4096, 4096);
 
-  pop_dynamic(&all_options);
+  all_options.pop_back();
   sys_var_add_options(&all_options, sys_var::PARSE_EARLY);
   add_plugin_options(&all_options, &mem_root);
-  sort_dynamic(&all_options, (qsort_cmp) option_cmp);
+  std::sort(all_options.begin(), all_options.end(), std::less<my_option>());
+  //sort_dynamic(&all_options, (qsort_cmp) option_cmp);
   add_terminator(&all_options);
 
-  my_print_help((my_option*) all_options.buffer);
-  my_print_variables((my_option*) all_options.buffer);
+  my_print_help(&all_options[0]);
+  my_print_variables(&all_options[0]);
 
   free_root(&mem_root, MYF(0));
-  delete_dynamic(&all_options);
+  all_options.clear();
 }
 
 static void usage(void)
@@ -7829,25 +7836,23 @@ static int get_options(int *argc_ptr, ch
   my_getopt_error_reporter= option_error_reporter;
 
   /* prepare all_options array */
-  my_init_dynamic_array(&all_options, sizeof(my_option),
-                        array_elements(my_long_options),
-                        array_elements(my_long_options)/4);
+  all_options.reserve(array_elements(my_long_options));
   for (my_option *opt= my_long_options;
        opt < my_long_options + array_elements(my_long_options) - 1;
        opt++)
-    insert_dynamic(&all_options, opt);
+    all_options.push_back(*opt);
   sys_var_add_options(&all_options, sys_var::PARSE_NORMAL);
   add_terminator(&all_options);
 
   /* Skip unknown options so that they may be processed later by plugins */
   my_getopt_skip_unknown= TRUE;
 
-  if ((ho_error= handle_options(argc_ptr, argv_ptr, (my_option*)(all_options.buffer),
+  if ((ho_error= handle_options(argc_ptr, argv_ptr, &all_options[0],
                                 mysqld_get_one_option)))
     return ho_error;
 
   if (!opt_help)
-    delete_dynamic(&all_options);
+    all_options.clear();
 
   /* Add back the program name handle_options removes */
   (*argc_ptr)++;

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2011-08-17 14:07:07 +0000
+++ b/sql/set_var.cc	2011-09-19 09:34:39 +0000
@@ -77,10 +77,8 @@ error:
   DBUG_RETURN(1);
 }
 
-int sys_var_add_options(DYNAMIC_ARRAY *long_options, int parse_flags)
+int sys_var_add_options(std::vector<my_option> *long_options, int parse_flags)
 {
-  uint saved_elements= long_options->elements;
-
   DBUG_ENTER("sys_var_add_options");
 
   for (sys_var *var=all_sys_vars.first; var; var= var->next)
@@ -93,7 +91,6 @@ int sys_var_add_options(DYNAMIC_ARRAY *l
 
 error:
   fprintf(stderr, "failed to initialize System variables");
-  long_options->elements= saved_elements;
   DBUG_RETURN(1);
 }
 

=== modified file 'sql/set_var.h'
--- a/sql/set_var.h	2011-08-17 14:07:07 +0000
+++ b/sql/set_var.h	2011-09-19 09:34:39 +0000
@@ -21,6 +21,7 @@
 */
 
 #include <my_getopt.h>
+#include <vector>
 
 class sys_var;
 class set_var;
@@ -127,10 +128,10 @@ public:
     }
     return true; // keep gcc happy
   }
-  bool register_option(DYNAMIC_ARRAY *array, int parse_flags)
+  bool register_option(std::vector<my_option> *array, int parse_flags)
   {
     return (option.id != -1) && (m_parse_flag & parse_flags) &&
-           insert_dynamic(array, &option);
+      (array->push_back(option), false);
   }
 
 private:
@@ -331,7 +332,7 @@ extern sys_var *Sys_autocommit_ptr;
 const CHARSET_INFO *get_old_charset_by_name(const char *old_name);
 
 int sys_var_init();
-int sys_var_add_options(DYNAMIC_ARRAY *long_options, int parse_flags);
+int sys_var_add_options(std::vector<my_option> *long_options, int parse_flags);
 void sys_var_end(void);
 
 #endif

=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc	2011-08-29 12:08:58 +0000
+++ b/sql/sql_plugin.cc	2011-09-19 09:34:39 +0000
@@ -3520,7 +3520,7 @@ err:
 ****************************************************************************/
 
 
-void add_plugin_options(DYNAMIC_ARRAY *options, MEM_ROOT *mem_root)
+void add_plugin_options(std::vector<my_option> *options, MEM_ROOT *mem_root)
 {
   struct st_plugin_int *p;
   my_option *opt;
@@ -3538,7 +3538,7 @@ void add_plugin_options(DYNAMIC_ARRAY *o
     /* Only options with a non-NULL comment are displayed in help text */
     for (;opt->name; opt++)
       if (opt->comment)
-        insert_dynamic(options, opt);
+        options->push_back(*opt);
   }
 }
 

=== modified file 'sql/sql_plugin.h'
--- a/sql/sql_plugin.h	2011-08-18 08:31:08 +0000
+++ b/sql/sql_plugin.h	2011-09-19 09:34:39 +0000
@@ -17,6 +17,7 @@
 #define _sql_plugin_h
 
 #include <my_global.h>
+#include <vector>
 
 /**
   the following #define adds server-only members to enum_mysql_show_type,
@@ -32,6 +33,7 @@
 
 #include "m_string.h"                       /* LEX_STRING */
 #include "my_alloc.h"                       /* MEM_ROOT */
+#include "my_getopt.h"
 
 class sys_var;
 enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED};
@@ -139,7 +141,7 @@ extern const LEX_STRING plugin_type_name
 
 extern int plugin_init(int *argc, char **argv, int init_flags);
 extern void plugin_shutdown(void);
-void add_plugin_options(DYNAMIC_ARRAY *options, MEM_ROOT *mem_root);
+void add_plugin_options(std::vector<my_option> *options, MEM_ROOT *mem_root);
 extern bool plugin_is_ready(const LEX_STRING *name, int type);
 #define my_plugin_lock_by_name(A,B,C) plugin_lock_by_name(A,B,C)
 #define my_plugin_lock_by_name_ci(A,B,C) plugin_lock_by_name(A,B,C)

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (tor.didriksen:3437 to 3438) Tor Didriksen20 Sep