mariadb/sql/vers_string.h
Vicențiu Ciorbaru 08c852026d Apply clang-tidy to remove empty constructors / destructors
This patch is the result of running
run-clang-tidy -fix -header-filter=.* -checks='-*,modernize-use-equals-default' .

Code style changes have been done on top. The result of this change
leads to the following improvements:

1. Binary size reduction.
* For a -DBUILD_CONFIG=mysql_release build, the binary size is reduced by
  ~400kb.
* A raw -DCMAKE_BUILD_TYPE=Release reduces the binary size by ~1.4kb.

2. Compiler can better understand the intent of the code, thus it leads
   to more optimization possibilities. Additionally it enabled detecting
   unused variables that had an empty default constructor but not marked
   so explicitly.

   Particular change required following this patch in sql/opt_range.cc

   result_keys, an unused template class Bitmap now correctly issues
   unused variable warnings.

   Setting Bitmap template class constructor to default allows the compiler
   to identify that there are no side-effects when instantiating the class.
   Previously the compiler could not issue the warning as it assumed Bitmap
   class (being a template) would not be performing a NO-OP for its default
   constructor. This prevented the "unused variable warning".
2023-02-09 16:09:08 +02:00

108 lines
2.9 KiB
C++

/*
Copyright (c) 2018, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef VERS_STRING_INCLUDED
#define VERS_STRING_INCLUDED
/*
LEX_CSTRING with comparison semantics.
*/
// db and table names: case sensitive (or insensitive) in table_alias_charset
struct Compare_table_names
{
int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const
{
DBUG_ASSERT(a.str[a.length] == 0);
DBUG_ASSERT(b.str[b.length] == 0);
return my_strnncoll(table_alias_charset,
(uchar*)a.str, a.length,
(uchar*)b.str, b.length);
}
};
// column names and other identifiers: case insensitive in system_charset_info
struct Compare_identifiers
{
int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const
{
DBUG_ASSERT(a.str != NULL);
DBUG_ASSERT(b.str != NULL);
DBUG_ASSERT(a.str[a.length] == 0);
DBUG_ASSERT(b.str[b.length] == 0);
return my_strcasecmp(system_charset_info, a.str, b.str);
}
};
class Lex_cstring : public LEX_CSTRING
{
public:
Lex_cstring()
{
str= NULL;
length= 0;
}
Lex_cstring(const char *_str, size_t _len)
{
str= _str;
length= _len;
}
Lex_cstring(const char *start, const char *end)
{
DBUG_ASSERT(start <= end);
str= start;
length= end - start;
}
void set(const char *_str, size_t _len)
{
str= _str;
length= _len;
}
};
template <class Compare>
struct Lex_cstring_with_compare : public Lex_cstring
{
public:
Lex_cstring_with_compare() = default;
Lex_cstring_with_compare(const char *_str, size_t _len) :
Lex_cstring(_str, _len)
{ }
Lex_cstring_with_compare(const LEX_STRING src) :
Lex_cstring(src.str, src.length)
{ }
Lex_cstring_with_compare(const LEX_CSTRING src) : Lex_cstring(src.str, src.length)
{ }
Lex_cstring_with_compare(const char *_str) : Lex_cstring(_str, strlen(_str))
{ }
bool streq(const Lex_cstring_with_compare& b) const
{
return Lex_cstring::length == b.length && 0 == Compare()(*this, b);
}
operator const char* () const
{
return str;
}
operator bool () const
{
return str != NULL;
}
};
typedef Lex_cstring_with_compare<Compare_identifiers> Lex_ident;
typedef Lex_cstring_with_compare<Compare_table_names> Lex_table_name;
#endif // VERS_STRING_INCLUDED