Skip to content

Commit a83afd8

Browse files
committed
cleanup: remove String::append_float
between set_real() and set_fcvt(), a third String method for real->string conversion looks definitely redundant
1 parent 88119ad commit a83afd8

File tree

3 files changed

+10
-45
lines changed

3 files changed

+10
-45
lines changed

sql/sql_string.cc

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -118,38 +118,6 @@ bool Binary_string::realloc_raw(size_t alloc_length)
118118
}
119119

120120

121-
static uint32 write_float_str_to_buff(char *buff, int buff_len,
122-
float num, uint decimals)
123-
{
124-
if (decimals >= FLOATING_POINT_DECIMALS)
125-
return (uint32)my_gcvt(num, MY_GCVT_ARG_FLOAT, buff_len - 1, buff, NULL);
126-
else
127-
return (uint32)my_fcvt(num, decimals, buff, NULL);
128-
}
129-
130-
bool String::append_float(float num, uint decimals)
131-
{
132-
uint dummy_errors;
133-
size_t len;
134-
DBUG_ASSERT(!std::isnan(num));
135-
DBUG_ASSERT(!std::isinf(num));
136-
if (realloc_with_extra_if_needed(str_length + FLOATING_POINT_BUFFER))
137-
return true;
138-
139-
if (charset()->mbminlen > 1)
140-
{
141-
char buff[FLOATING_POINT_BUFFER];
142-
len= write_float_str_to_buff(buff, sizeof(buff), num, decimals);
143-
str_length+= copy_and_convert(Ptr + str_length, len, charset(), buff, len,
144-
&my_charset_latin1, &dummy_errors);
145-
}
146-
else
147-
str_length+= write_float_str_to_buff(Ptr + str_length,
148-
FLOATING_POINT_BUFFER, num, decimals);
149-
return false;
150-
}
151-
152-
153121
bool String::set_int(longlong num, bool unsigned_flag, CHARSET_INFO *cs)
154122
{
155123
/*
@@ -242,7 +210,8 @@ bool Binary_string::set_fcvt(double num, uint decimals)
242210
}
243211

244212

245-
bool String::set_real(double num,uint decimals, CHARSET_INFO *cs)
213+
bool String::set_real_with_type(double num, uint decimals, CHARSET_INFO *cs,
214+
my_gcvt_arg_type type)
246215
{
247216
char buff[FLOATING_POINT_BUFFER];
248217
uint dummy_errors;
@@ -251,12 +220,11 @@ bool String::set_real(double num,uint decimals, CHARSET_INFO *cs)
251220
set_charset(cs);
252221
if (decimals >= FLOATING_POINT_DECIMALS)
253222
{
254-
len= my_gcvt(num, MY_GCVT_ARG_DOUBLE, sizeof(buff) - 1, buff, NULL);
223+
len= my_gcvt(num, type, sizeof(buff) - 1, buff, NULL);
255224
return copy(buff, (uint)len, &my_charset_latin1, cs, &dummy_errors);
256225
}
257226
len= my_fcvt(num, decimals, buff, NULL);
258-
return copy(buff, (uint32) len, &my_charset_latin1, cs,
259-
&dummy_errors);
227+
return copy(buff, (uint32) len, &my_charset_latin1, cs, &dummy_errors);
260228
}
261229

262230

sql/sql_string.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,11 @@ class String: public Charset, public Binary_string
897897
bool set(ulong num, CHARSET_INFO *cs) { return set_int(num, true, cs); }
898898
bool set(longlong num, CHARSET_INFO *cs) { return set_int(num, false, cs); }
899899
bool set(ulonglong num, CHARSET_INFO *cs) { return set_int((longlong)num, true, cs); }
900-
bool set_real(double num,uint decimals, CHARSET_INFO *cs);
900+
bool set_real_with_type(double num, uint decimals, CHARSET_INFO *cs, my_gcvt_arg_type);
901+
bool set_real(double num,uint decimals, CHARSET_INFO *cs)
902+
{ return set_real_with_type(num,decimals,cs,MY_GCVT_ARG_DOUBLE); }
903+
bool set_real(float num,uint decimals, CHARSET_INFO *cs)
904+
{ return set_real_with_type(num,decimals,cs,MY_GCVT_ARG_FLOAT); }
901905
bool set_fcvt(double num, uint decimals)
902906
{
903907
set_charset(&my_charset_latin1);
@@ -1012,11 +1016,6 @@ class String: public Charset, public Binary_string
10121016
return Binary_string::append(s);
10131017
}
10141018

1015-
// Append a float value to the string keeping the string's charset.
1016-
//
1017-
// The float value must not be NaN or Inf, it will be represented as 0 in
1018-
// that case.
1019-
bool append_float(float num, uint decimals);
10201019
inline bool append(char chr)
10211020
{
10221021
return Binary_string::append_char(chr);

sql/sql_type.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ Type_handler_data *type_handler_data= NULL;
331331

332332
bool Float::to_string(String *val_buffer, uint dec) const
333333
{
334-
val_buffer->set_charset(&my_charset_numeric);
335-
val_buffer->length(0);
336-
return val_buffer->append_float(m_value, dec);
334+
return val_buffer->set_real(m_value, dec, &my_charset_numeric);
337335
}
338336

339337

0 commit comments

Comments
 (0)