← Back to team overview

maria-developers team mailing list archive

Re: On bb-10.6-monty work

 

Hi!

On Fri, Sep 11, 2020 at 8:11 AM Nikita Malyavin
<nikitamalyavin@xxxxxxxxx> wrote:

<cut>

> > -static void _ma_check_print(HA_CHECK *param, const char* msg_type,
> > +static void _ma_check_print(HA_CHECK *param, const LEX_CSTRING *msg_type,
> >                              const char *msgbuf)
>
> I would also suggest passing LEX_CSTRING by value. Its size is not more than
> two pointers, so it can be passed by registers by most ABIs.

I greatly prefer to always pass things as pointers to ensure that one
doesn't accidentally
pass bug structures on the stack (a problem we have had several times).
Yes, it's true that for a simple function that directly uses the
LEX_CSTRING then it's
not a big difference in speed or size when calling with LEX_CSTRING. However if
the LEX_CSTRING is passed down to other functions that in their turn do the same
then things will start to matter.
Because the caller should not know how deep the called function will
go, I prefer
to use pointers in most cases.


> Passing it by a pointer add a second dereference, which is costy

Not really as when you pass the LEX_CSTRING on the stack, you have to
read and copy
the pointers.  It's less code to do the deference of LEX_CSTRING in
the call than in all the
100+ places that may call the function.


> >  {
> > -  if (msg_type == MA_CHECK_INFO)
> > +  if (msg_type == &MA_CHECK_INFO)
> >      sql_print_information("%s.%s: %s", param->db_name, param->table_name,
> >                            msgbuf);
> > -  else if (msg_type == MA_CHECK_WARNING)
> > +  else if (msg_type == &MA_CHECK_WARNING)
> >      sql_print_warning("%s.%s: %s", param->db_name, param->table_name,
> >                        msgbuf);

Not also that the above code would not work if the LEX_CSTRING would
be an object on the stack.

Regards,
Monty


References