Commit 7d6b55b9 authored by Monty's avatar Monty

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()
parent 862e602b
......@@ -62,9 +62,9 @@
bool check_reserved_words(const LEX_CSTRING *name)
{
if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
!my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
!my_strcasecmp(system_charset_info, name->str, "SESSION"))
if (lex_string_eq(name, STRING_WITH_LEN("GLOBAL")) ||
lex_string_eq(name, STRING_WITH_LEN("LOCAL")) ||
lex_string_eq(name, STRING_WITH_LEN("SESSION")))
return TRUE;
return FALSE;
}
......
......@@ -21,6 +21,7 @@
typedef struct st_mysql_const_lex_string LEX_CSTRING;
/* Functions to compare if two lex strings are equal */
static inline bool lex_string_cmp(CHARSET_INFO *charset, const LEX_CSTRING *a,
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
*/
static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b)
{
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
character set is ASCII (like for plugin names)
*/
static inline bool lex_string_eq(const LEX_CSTRING *a, const LEX_CSTRING *b)
{
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
(field names, user variables, etc - but *not* table names)
To be used when calling lex_string_eq with STRING_WITH_LEN() as second
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 */
......@@ -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)
{
// 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;
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;
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;
else
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)
{
// 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;
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;
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;
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;
else
return true;
......
......@@ -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 (!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);
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 create_item_ident_nosp(thd, name);
......
......@@ -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
*/
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));
DBUG_RETURN(TRUE);
......
......@@ -14106,9 +14106,9 @@ opt_format_json:
/* empty */ {}
| 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;
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);
else
my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "EXPLAIN",
......@@ -17466,9 +17466,9 @@ opt_format_xid:
/* empty */ { $$= false; }
| FORMAT_SYM '=' ident_or_text
{
if (!my_strcasecmp(system_charset_info, $3.str, "SQL"))
if (lex_string_eq(&$3, STRING_WITH_LEN("SQL")))
$$= true;
else if (!my_strcasecmp(system_charset_info, $3.str, "RAW"))
else if (lex_string_eq(&$3, STRING_WITH_LEN("RAW")))
$$= false;
else
{
......
......@@ -13848,9 +13848,9 @@ opt_format_json:
/* empty */ {}
| 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;
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);
else
my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "EXPLAIN",
......@@ -17332,9 +17332,9 @@ opt_format_xid:
/* empty */ { $$= false; }
| FORMAT_SYM '=' ident_or_text
{
if (!my_strcasecmp(system_charset_info, $3.str, "SQL"))
if (lex_string_eq(&$3, STRING_WITH_LEN("SQL")))
$$= true;
else if (!my_strcasecmp(system_charset_info, $3.str, "RAW"))
else if (lex_string_eq(&$3, STRING_WITH_LEN("RAW")))
$$= false;
else
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment