Details
-
Task
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
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);