[MDEV-23270] Remove a String parameter from Protocol::store(double/float) Created: 2020-07-23  Updated: 2020-10-06  Resolved: 2020-08-14

Status: Closed
Project: MariaDB Server
Component/s: Protocol
Fix Version/s: 10.5.7

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates

 Description   

As agreed during a discussion with Monty, let's change the Protocol API from:

virtual bool store(float nr, uint32 decimals, String *buffer);
virtual bool store(double from, uint32 decimals, String *buffer);

to

virtual bool store_float(float nr, uint32 decimals);
virtual bool store_double(double from, uint32 decimals);

I.e.:

  • Remove the String* argument
  • Rename store(float) and store(double) to store_float() and store_double(), to avoid ambiguity, and to avoid explicit cast in calls.

Rationale to remove the String* argument:

  • The String buffer is only needed for Protocol_text. Instead of creating a String buffer on stack for every Field sent, the buffer will go to as a protected member to the class:

    class Protocol_text :public Protocol
    {
      StringBuffer<FLOATING_POINT_BUFFER> buffer;
    public:
    

    so will be created only once per session. This should give a slight performance improvement.

  • It will remove a confusing code, e.g.:

     bool Field_double::send_binary(Protocol *protocol)
     {
    -  return protocol->store((double) Field_double::val_real(), dec, (String*) 0);
    +  return protocol->store_double(Field_double::val_real(), dec);
     }
    

    A reader has questions when seeing this code: why a NULL String is passed? when it's important to pass a non-NULL pointer?

  • It will make the code more symmetric across various data types.
    Notice, other methods do not have any String buffer parameter:

      virtual bool store_tiny(longlong from);
      virtual bool store_short(longlong from);
      virtual bool store_long(longlong from);
      virtual bool store_longlong(longlong from, bool unsigned_flag);
      virtual bool store_decimal(const my_decimal *);
      virtual bool store_str(const char *from, size_t length,
                             CHARSET_INFO *fromcs,
                             CHARSET_INFO *tocs);
      virtual bool store(MYSQL_TIME *time, int decimals);
      virtual bool store_date(MYSQL_TIME *time);
      virtual bool store_time(MYSQL_TIME *time, int decimals);
    


Generated at Thu Feb 08 09:21:09 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.