Commit a0521cd7 authored by unknown's avatar unknown
Browse files

Polishing: use constants instead of magic numbers.


include/my_global.h:
  Introduce constants to be used instead of magic numbers.
sql/field.cc:
  Polishing: use contants instead of magic numbers.
sql/ha_innodb.cc:
  Polishing: use contants instead of magic numbers.
sql/handler.cc:
  Polishing: use contants instead of magic numbers.
sql/item.cc:
  Polishing: use contants instead of magic numbers.
sql/item.h:
  Polishing: use contants instead of magic numbers.
sql/item_func.cc:
  Polishing: use contants instead of magic numbers.
sql/item_subselect.cc:
  Polishing: use contants instead of magic numbers.
sql/log_event.cc:
  Polishing: use contants instead of magic numbers.
sql/sql_base.cc:
  Polishing: use contants instead of magic numbers.
sql/sql_select.cc:
  Polishing: use contants instead of magic numbers.
sql/sql_show.cc:
  Polishing: use contants instead of magic numbers.
sql/sql_table.cc:
  Polishing: use contants instead of magic numbers.
parent 98056987
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1357,4 +1357,13 @@ do { doubleget_union _tmp; \
#define NO_EMBEDDED_ACCESS_CHECKS
#endif


/* Length of decimal number represented by INT32. */

#define MY_INT32_NUM_DECIMAL_DIGITS 11

/* Length of decimal number represented by INT64. */

#define MY_INT64_NUM_DECIMAL_DIGITS 21

#endif /* my_global_h */
+3 −3
Original line number Diff line number Diff line
@@ -1203,12 +1203,12 @@ static bool test_if_real(const char *str,int length, CHARSET_INFO *cs)
String *Field::val_int_as_str(String *val_buffer, my_bool unsigned_val)
{
  CHARSET_INFO *cs= &my_charset_bin;
  uint length= 21;
  uint length;
  longlong value= val_int();
  if (val_buffer->alloc(length))
  if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
    return 0;
  length= (uint) (*cs->cset->longlong10_to_str)(cs, (char*) val_buffer->ptr(),
                                                length,
                                                MY_INT64_NUM_DECIMAL_DIGITS,
                                                unsigned_val ? 10 : -10,
                                                value);
  val_buffer->length(length);
+8 −8
Original line number Diff line number Diff line
@@ -6391,16 +6391,16 @@ innodb_mutex_show_status(
#ifdef UNIV_DEBUG
  field_list.push_back(new Item_empty_string("Mutex", FN_REFLEN));
  field_list.push_back(new Item_empty_string("Module", FN_REFLEN));
  field_list.push_back(new Item_uint("Count", 21));
  field_list.push_back(new Item_uint("Spin_waits", 21));
  field_list.push_back(new Item_uint("Spin_rounds", 21));
  field_list.push_back(new Item_uint("OS_waits", 21));
  field_list.push_back(new Item_uint("OS_yields", 21));
  field_list.push_back(new Item_uint("OS_waits_time", 21));
  field_list.push_back(new Item_uint("Count", MY_INT64_NUM_DECIMAL_DIGITS));
  field_list.push_back(new Item_uint("Spin_waits", MY_INT64_NUM_DECIMAL_DIGITS));
  field_list.push_back(new Item_uint("Spin_rounds", MY_INT64_NUM_DECIMAL_DIGITS));
  field_list.push_back(new Item_uint("OS_waits", MY_INT64_NUM_DECIMAL_DIGITS));
  field_list.push_back(new Item_uint("OS_yields", MY_INT64_NUM_DECIMAL_DIGITS));
  field_list.push_back(new Item_uint("OS_waits_time", MY_INT64_NUM_DECIMAL_DIGITS));
#else /* UNIV_DEBUG */
  field_list.push_back(new Item_empty_string("File", FN_REFLEN));
  field_list.push_back(new Item_uint("Line", 21));
  field_list.push_back(new Item_uint("OS_waits", 21));
  field_list.push_back(new Item_uint("Line", MY_INT64_NUM_DECIMAL_DIGITS));
  field_list.push_back(new Item_uint("OS_waits", MY_INT64_NUM_DECIMAL_DIGITS));
#endif /* UNIV_DEBUG */

  if (protocol->send_fields(&field_list,
+3 −3
Original line number Diff line number Diff line
@@ -1082,9 +1082,9 @@ bool mysql_xa_recover(THD *thd)
  XID_STATE *xs;
  DBUG_ENTER("mysql_xa_recover");

  field_list.push_back(new Item_int("formatID",0,11));
  field_list.push_back(new Item_int("gtrid_length",0,11));
  field_list.push_back(new Item_int("bqual_length",0,11));
  field_list.push_back(new Item_int("formatID", 0, MY_INT32_NUM_DECIMAL_DIGITS));
  field_list.push_back(new Item_int("gtrid_length", 0, MY_INT32_NUM_DECIMAL_DIGITS));
  field_list.push_back(new Item_int("bqual_length", 0, MY_INT32_NUM_DECIMAL_DIGITS));
  field_list.push_back(new Item_empty_string("data",XIDDATASIZE));

  if (protocol->send_fields(&field_list,
+3 −3
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ void
Hybrid_type_traits_integer::fix_length_and_dec(Item *item, Item *arg) const
{
  item->decimals= 0;
  item->max_length= 21;
  item->max_length= MY_INT64_NUM_DECIMAL_DIGITS;
  item->unsigned_flag= 0;
}

@@ -2491,7 +2491,7 @@ bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
      item_result_type= REAL_RESULT;
      break;
    case INT_RESULT:
      set_int(*(longlong*)entry->value, 21);
      set_int(*(longlong*)entry->value, MY_INT64_NUM_DECIMAL_DIGITS);
      item_type= Item::INT_ITEM;
      item_result_type= INT_RESULT;
      break;
@@ -6535,7 +6535,7 @@ uint32 Item_type_holder::display_length(Item *item)
  case MYSQL_TYPE_SHORT:
    return 6;
  case MYSQL_TYPE_LONG:
    return 11;
    return MY_INT32_NUM_DECIMAL_DIGITS;
  case MYSQL_TYPE_FLOAT:
    return 25;
  case MYSQL_TYPE_DOUBLE:
Loading