Commit d1851b30 authored by Monty's avatar Monty

Code cleanups

- Replace "class Repeat_count" with function call.
  There is no reason for this class to exists. More complex and more
  code than doing a function!  In addition the code didn't match what
  the val() function was doing.

Other things:
- Fixed compiler failure in print_cached_tables_callback()
parent dc75f3e0
......@@ -58,25 +58,21 @@ C_MODE_END
size_t username_char_length= 80;
/*
Calculate max length of string from length argument to LEFT and RIGHT
*/
class Repeat_count
static uint32 max_length_for_string(Item *item)
{
ulonglong m_count;
public:
Repeat_count(Item *item)
:m_count(0)
ulonglong length= item->val_int();
/* Note that if value is NULL, val_int() returned 0 */
if (length > (ulonglong) INT_MAX32)
{
Longlong_hybrid nr= item->to_longlong_hybrid();
if (!item->null_value && !nr.neg())
{
// Assume that the maximum length of a String is < INT_MAX32
m_count= (ulonglong) nr.value();
if (m_count > (ulonglong) INT_MAX32)
m_count= (ulonglong) INT_MAX32;
}
/* Limit string length to maxium string length in MariaDB (2G) */
length= item->unsigned_flag ? (ulonglong) INT_MAX32 : 0;
}
ulonglong count() const { return m_count; }
};
return (uint32) length;
}
/*
......@@ -1656,8 +1652,8 @@ void Item_str_func::left_right_max_length()
uint32 char_length= args[0]->max_char_length();
if (args[1]->const_item() && !args[1]->is_expensive())
{
Repeat_count tmp(args[1]);
set_if_smaller(char_length, (uint) tmp.count());
uint32 length= max_length_for_string(args[1]);
set_if_smaller(char_length, length);
}
fix_char_length(char_length);
}
......@@ -3025,8 +3021,8 @@ bool Item_func_repeat::fix_length_and_dec()
DBUG_ASSERT(collation.collation != NULL);
if (args[1]->const_item() && !args[1]->is_expensive())
{
Repeat_count tmp(args[1]);
ulonglong char_length= (ulonglong) args[0]->max_char_length() * tmp.count();
uint32 length= max_length_for_string(args[1]);
ulonglong char_length= (ulonglong) args[0]->max_char_length() * length;
fix_char_length_ulonglong(char_length);
return false;
}
......@@ -3099,7 +3095,7 @@ bool Item_func_space::fix_length_and_dec()
collation.set(default_charset(), DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
if (args[0]->const_item() && !args[0]->is_expensive())
{
fix_char_length_ulonglong(Repeat_count(args[0]).count());
fix_char_length_ulonglong(max_length_for_string(args[0]));
return false;
}
max_length= MAX_BLOB_WIDTH;
......@@ -3218,7 +3214,7 @@ bool Item_func_pad::fix_length_and_dec()
DBUG_ASSERT(collation.collation->mbmaxlen > 0);
if (args[1]->const_item() && !args[1]->is_expensive())
{
fix_char_length_ulonglong(Repeat_count(args[1]).count());
fix_char_length_ulonglong(max_length_for_string(args[1]));
return false;
}
max_length= MAX_BLOB_WIDTH;
......
......@@ -88,9 +88,8 @@ static my_bool print_cached_tables_callback(TDC_element *element,
while ((entry= it++))
{
THD *in_use= entry->in_use;
printf("%-14.14s %-32s%6lu%8ld%6d %s\n",
printf("%-14.14s %-32s%8ld%6d %s\n",
entry->s->db.str, entry->s->table_name.str,
(ulong) element->version,
in_use ? (long) in_use->thread_id : (long) 0,
entry->db_stat ? 1 : 0,
in_use ? lock_descriptions[(int)entry->reginfo.lock_type] :
......
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