1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Added version of lex_string_eq that compares with const char *

Change all my_stcasecmp() calls that uses lexical keywords to use
lex_string_eq. This is faster as we only call strcasecmp() for
strings of different lengths.

Removed not used function lex_string_syseq()
This commit is contained in:
Monty
2018-04-30 14:24:48 +03:00
parent 862e602b5a
commit 7d6b55b99a
7 changed files with 31 additions and 25 deletions

View File

@ -62,9 +62,9 @@
bool check_reserved_words(const LEX_CSTRING *name) bool check_reserved_words(const LEX_CSTRING *name)
{ {
if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") || if (lex_string_eq(name, STRING_WITH_LEN("GLOBAL")) ||
!my_strcasecmp(system_charset_info, name->str, "LOCAL") || lex_string_eq(name, STRING_WITH_LEN("LOCAL")) ||
!my_strcasecmp(system_charset_info, name->str, "SESSION")) lex_string_eq(name, STRING_WITH_LEN("SESSION")))
return TRUE; return TRUE;
return FALSE; return FALSE;
} }

View File

@ -21,6 +21,7 @@
typedef struct st_mysql_const_lex_string LEX_CSTRING; typedef struct st_mysql_const_lex_string LEX_CSTRING;
/* Functions to compare if two lex strings are equal */ /* Functions to compare if two lex strings are equal */
static inline bool lex_string_cmp(CHARSET_INFO *charset, const LEX_CSTRING *a, static inline bool lex_string_cmp(CHARSET_INFO *charset, const LEX_CSTRING *a,
const LEX_CSTRING *b) const LEX_CSTRING *b)
{ {
@ -30,6 +31,7 @@ static inline bool lex_string_cmp(CHARSET_INFO *charset, const LEX_CSTRING *a,
/* /*
Compare to LEX_CSTRING's and return 0 if equal Compare to LEX_CSTRING's and return 0 if equal
*/ */
static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b) static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b)
{ {
return (a->length != b->length || return (a->length != b->length ||
@ -40,6 +42,7 @@ static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b)
Compare if two LEX_CSTRING are equal. Assumption is that Compare if two LEX_CSTRING are equal. Assumption is that
character set is ASCII (like for plugin names) character set is ASCII (like for plugin names)
*/ */
static inline bool lex_string_eq(const LEX_CSTRING *a, const LEX_CSTRING *b) static inline bool lex_string_eq(const LEX_CSTRING *a, const LEX_CSTRING *b)
{ {
if (a->length != b->length) if (a->length != b->length)
@ -48,12 +51,15 @@ static inline bool lex_string_eq(const LEX_CSTRING *a, const LEX_CSTRING *b)
} }
/* /*
Compare if two LEX_CSTRING are equal in system character set To be used when calling lex_string_eq with STRING_WITH_LEN() as second
(field names, user variables, etc - but *not* table names) argument
*/ */
static inline bool lex_string_syseq(const LEX_CSTRING *a, const LEX_CSTRING *b)
static inline bool lex_string_eq(const LEX_CSTRING *a, const char *b, size_t b_length)
{ {
return lex_string_cmp(system_charset_info, a, b) == 0; if (a->length != b_length)
return 0; /* Different */
return strcasecmp(a->str, b) == 0;
} }
#endif /* LEX_STRING_INCLUDED */ #endif /* LEX_STRING_INCLUDED */

View File

@ -54,11 +54,11 @@ Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
bool Alter_info::set_requested_algorithm(const LEX_CSTRING *str) bool Alter_info::set_requested_algorithm(const LEX_CSTRING *str)
{ {
// To avoid adding new keywords to the grammar, we match strings here. // To avoid adding new keywords to the grammar, we match strings here.
if (!my_strcasecmp(system_charset_info, str->str, "INPLACE")) if (lex_string_eq(str, STRING_WITH_LEN("INPLACE")))
requested_algorithm= ALTER_TABLE_ALGORITHM_INPLACE; requested_algorithm= ALTER_TABLE_ALGORITHM_INPLACE;
else if (!my_strcasecmp(system_charset_info, str->str, "COPY")) else if (lex_string_eq(str, STRING_WITH_LEN("COPY")))
requested_algorithm= ALTER_TABLE_ALGORITHM_COPY; requested_algorithm= ALTER_TABLE_ALGORITHM_COPY;
else if (!my_strcasecmp(system_charset_info, str->str, "DEFAULT")) else if (lex_string_eq(str, STRING_WITH_LEN("DEFAULT")))
requested_algorithm= ALTER_TABLE_ALGORITHM_DEFAULT; requested_algorithm= ALTER_TABLE_ALGORITHM_DEFAULT;
else else
return true; return true;
@ -69,13 +69,13 @@ bool Alter_info::set_requested_algorithm(const LEX_CSTRING *str)
bool Alter_info::set_requested_lock(const LEX_CSTRING *str) bool Alter_info::set_requested_lock(const LEX_CSTRING *str)
{ {
// To avoid adding new keywords to the grammar, we match strings here. // To avoid adding new keywords to the grammar, we match strings here.
if (!my_strcasecmp(system_charset_info, str->str, "NONE")) if (lex_string_eq(str, STRING_WITH_LEN("NONE")))
requested_lock= ALTER_TABLE_LOCK_NONE; requested_lock= ALTER_TABLE_LOCK_NONE;
else if (!my_strcasecmp(system_charset_info, str->str, "SHARED")) else if (lex_string_eq(str, STRING_WITH_LEN("SHARED")))
requested_lock= ALTER_TABLE_LOCK_SHARED; requested_lock= ALTER_TABLE_LOCK_SHARED;
else if (!my_strcasecmp(system_charset_info, str->str, "EXCLUSIVE")) else if (lex_string_eq(str, STRING_WITH_LEN("EXCLUSIVE")))
requested_lock= ALTER_TABLE_LOCK_EXCLUSIVE; requested_lock= ALTER_TABLE_LOCK_EXCLUSIVE;
else if (!my_strcasecmp(system_charset_info, str->str, "DEFAULT")) else if (lex_string_eq(str, STRING_WITH_LEN("DEFAULT")))
requested_lock= ALTER_TABLE_LOCK_DEFAULT; requested_lock= ALTER_TABLE_LOCK_DEFAULT;
else else
return true; return true;

View File

@ -7038,9 +7038,9 @@ Item *LEX::create_item_ident_sp(THD *thd, Lex_ident_sys_st *name,
if (thd->variables.sql_mode & MODE_ORACLE) if (thd->variables.sql_mode & MODE_ORACLE)
{ {
if (!my_strcasecmp(system_charset_info, name->str, "SQLCODE")) if (lex_string_eq(name, STRING_WITH_LEN("SQLCODE")))
return new (thd->mem_root) Item_func_sqlcode(thd); return new (thd->mem_root) Item_func_sqlcode(thd);
if (!my_strcasecmp(system_charset_info, name->str, "SQLERRM")) if (lex_string_eq(name, STRING_WITH_LEN("SQLERRM")))
return new (thd->mem_root) Item_func_sqlerrm(thd); return new (thd->mem_root) Item_func_sqlerrm(thd);
} }
return create_item_ident_nosp(thd, name); return create_item_ident_nosp(thd, name);

View File

@ -431,7 +431,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
/* /*
We don't allow creating triggers on tables in the 'mysql' schema We don't allow creating triggers on tables in the 'mysql' schema
*/ */
if (create && !my_strcasecmp(system_charset_info, "mysql", tables->db.str)) if (create && lex_string_eq(&tables->db, STRING_WITH_LEN("mysql")))
{ {
my_error(ER_NO_TRIGGERS_ON_SYSTEM_SCHEMA, MYF(0)); my_error(ER_NO_TRIGGERS_ON_SYSTEM_SCHEMA, MYF(0));
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);

View File

@ -14106,9 +14106,9 @@ opt_format_json:
/* empty */ {} /* empty */ {}
| FORMAT_SYM '=' ident_or_text | FORMAT_SYM '=' ident_or_text
{ {
if (!my_strcasecmp(system_charset_info, $3.str, "JSON")) if (lex_string_eq(&$3, STRING_WITH_LEN("JSON")))
Lex->explain_json= true; Lex->explain_json= true;
else if (!my_strcasecmp(system_charset_info, $3.str, "TRADITIONAL")) else if (lex_string_eq(&$3, STRING_WITH_LEN("TRADITIONAL")))
DBUG_ASSERT(Lex->explain_json==false); DBUG_ASSERT(Lex->explain_json==false);
else else
my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "EXPLAIN", my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "EXPLAIN",
@ -17466,9 +17466,9 @@ opt_format_xid:
/* empty */ { $$= false; } /* empty */ { $$= false; }
| FORMAT_SYM '=' ident_or_text | FORMAT_SYM '=' ident_or_text
{ {
if (!my_strcasecmp(system_charset_info, $3.str, "SQL")) if (lex_string_eq(&$3, STRING_WITH_LEN("SQL")))
$$= true; $$= true;
else if (!my_strcasecmp(system_charset_info, $3.str, "RAW")) else if (lex_string_eq(&$3, STRING_WITH_LEN("RAW")))
$$= false; $$= false;
else else
{ {

View File

@ -13848,9 +13848,9 @@ opt_format_json:
/* empty */ {} /* empty */ {}
| FORMAT_SYM '=' ident_or_text | FORMAT_SYM '=' ident_or_text
{ {
if (!my_strcasecmp(system_charset_info, $3.str, "JSON")) if (lex_string_eq(&$3, STRING_WITH_LEN("JSON")))
Lex->explain_json= true; Lex->explain_json= true;
else if (!my_strcasecmp(system_charset_info, $3.str, "TRADITIONAL")) else if (lex_string_eq(&$3, STRING_WITH_LEN("TRADITIONAL")))
DBUG_ASSERT(Lex->explain_json==false); DBUG_ASSERT(Lex->explain_json==false);
else else
my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "EXPLAIN", my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "EXPLAIN",
@ -17332,9 +17332,9 @@ opt_format_xid:
/* empty */ { $$= false; } /* empty */ { $$= false; }
| FORMAT_SYM '=' ident_or_text | FORMAT_SYM '=' ident_or_text
{ {
if (!my_strcasecmp(system_charset_info, $3.str, "SQL")) if (lex_string_eq(&$3, STRING_WITH_LEN("SQL")))
$$= true; $$= true;
else if (!my_strcasecmp(system_charset_info, $3.str, "RAW")) else if (lex_string_eq(&$3, STRING_WITH_LEN("RAW")))
$$= false; $$= false;
else else
{ {