List:Commits« Previous MessageNext Message »
From:Konstantin Osipov Date:January 20 2010 10:40am
Subject:bzr commit into mysql-5.6-next-mr branch (kostja:3058) Bug#38924
Bug#46272
View as plain text  
#At file:///opt/local/work/next-4284-stage/ based on revid:kostja@stripped

 3058 Konstantin Osipov	2010-01-20
      Bug#46272/Bug#38924 review fixes in progress.
      Update MDL_key class to be more compact.
      Simplify the comparison method, used when sorting MDL_keys.

    modified:
      sql/mdl.h
=== modified file 'sql/mdl.h'
--- a/sql/mdl.h	2010-01-20 10:17:29 +0000
+++ b/sql/mdl.h	2010-01-20 10:40:14 +0000
@@ -96,7 +96,8 @@ public:
   { return (enum_mdl_namespace)(m_ptr[0]); }
 
   /**
-    Construct a metadata lock key from a triplet (mdl_namespace, database and name).
+    Construct a metadata lock key from a triplet (mdl_namespace,
+    database and name).
 
     @remark The key for a table is <mdl_namespace>+<database name>+<table name>
 
@@ -105,11 +106,12 @@ public:
     @param  name          Name of of the object
     @param  key           Where to store the the MDL key.
   */
-  void mdl_key_init(enum_mdl_namespace mdl_namespace, const char *db, const char *name)
+  void mdl_key_init(enum_mdl_namespace mdl_namespace,
+                    const char *db, const char *name)
   {
     m_ptr[0]= (char) mdl_namespace;
-    m_db_name_length= (uint) (strmov(m_ptr + 1, db) - m_ptr - 1);
-    m_length= (uint) (strmov(m_ptr + m_db_name_length + 2, name) - m_ptr + 1);
+    m_db_name_length= (uint16) (strmov(m_ptr + 1, db) - m_ptr - 1);
+    m_length= (uint16) (strmov(m_ptr + m_db_name_length + 2, name) - m_ptr + 1);
   }
   void mdl_key_init(const MDL_key *rhs)
   {
@@ -127,31 +129,29 @@ public:
   */
   int cmp(const MDL_key *rhs) const
   {
-    int res;
-    if ((res= memcmp(m_ptr, rhs->m_ptr, min(m_length, rhs->m_length))))
-      return res;
-    else if (m_length < rhs->m_length)
-      return -1;
-    else if (m_length > rhs->m_length)
-      return 1;
-    else
-      return 0;
+    /*
+      The key buffer is always '\0'-terminated. Since key
+      character set is utf-8, we can safely assume that no
+      character starts with a zero byte.
+    */
+    return memcmp(m_ptr, rhs->m_ptr, min(m_length, rhs->m_length)+1);
   }
 
   MDL_key(const MDL_key *rhs)
   {
     mdl_key_init(rhs);
   }
-  MDL_key(enum_mdl_namespace namespace_arg, const char *db_arg, const char *name_arg)
+  MDL_key(enum_mdl_namespace namespace_arg,
+          const char *db_arg, const char *name_arg)
   {
     mdl_key_init(namespace_arg, db_arg, name_arg);
   }
   MDL_key() {} /* To use when part of MDL_request. */
 
 private:
+  uint16 m_length;
+  uint16 m_db_name_length;
   char m_ptr[MAX_MDLKEY_LENGTH];
-  uint m_length;
-  uint m_db_name_length;
 private:
   MDL_key(const MDL_key &);                     /* not implemented */
   MDL_key &operator=(const MDL_key &);          /* not implemented */


Attachment: [text/bzr-bundle] bzr/kostja@sun.com-20100120104014-koviawcs5pgu0s89.bundle
Thread
bzr commit into mysql-5.6-next-mr branch (kostja:3058) Bug#38924Bug#46272Konstantin Osipov20 Jan