Skip to content

Commit 949fed5

Browse files
committed
cleanup: get_float convenience helper
more helpers like that can be added as needed
1 parent 115d3e0 commit 949fed5

File tree

7 files changed

+16
-21
lines changed

7 files changed

+16
-21
lines changed

include/my_byteorder.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
along with this program; if not, write to the Free Software
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
1818

19+
#include <string.h>
1920

2021
/*
2122
Macro for reading 32-bit integer from network byte order (big-endian)
@@ -51,4 +52,12 @@
5152
#include "little_endian.h"
5253
#endif
5354

55+
/* convenienve helpers */
56+
static inline float get_float(const void *from)
57+
{
58+
float to;
59+
float4get(to, ((const uchar*)from));
60+
return to;
61+
}
62+
5463
#endif /* MY_BYTEORDER_INCLUDED */

libmysqld/libmysql.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3658,9 +3658,7 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
36583658
}
36593659
case MYSQL_TYPE_FLOAT:
36603660
{
3661-
float value;
3662-
float4get(value,*row);
3663-
fetch_float_with_conversion(param, field, value, MY_GCVT_ARG_FLOAT);
3661+
fetch_float_with_conversion(param, field, get_float(*row), MY_GCVT_ARG_FLOAT);
36643662
*row+= 4;
36653663
break;
36663664
}

sql/field.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4862,16 +4862,12 @@ int Field_float::store(longlong nr, bool unsigned_val)
48624862
double Field_float::val_real(void)
48634863
{
48644864
DBUG_ASSERT(marked_for_read());
4865-
float j;
4866-
float4get(j,ptr);
4867-
return ((double) j);
4865+
return ((double) get_float(ptr));
48684866
}
48694867

48704868
longlong Field_float::val_int(void)
48714869
{
4872-
float j;
4873-
float4get(j,ptr);
4874-
return Converter_double_to_longlong(j, false).result();
4870+
return Converter_double_to_longlong(get_float(ptr), false).result();
48754871
}
48764872

48774873

sql/log_event_client.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,8 @@ log_event_print_value(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info,
632632
if (!ptr)
633633
goto return_null;
634634

635-
float fl;
636-
float4get(fl, ptr);
637635
char tmp[320];
638-
sprintf(tmp, "%-20g", (double) fl);
636+
sprintf(tmp, "%-20g", (double) get_float(ptr));
639637
my_b_printf(file, "%s", tmp); /* my_snprintf doesn't support %-20g */
640638
return 4;
641639
}

storage/heap/hp_hash.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,7 @@ uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key,
635635

636636
if (seg->type == HA_KEYTYPE_FLOAT)
637637
{
638-
float nr;
639-
float4get(nr, pos);
640-
if (isnan(nr))
638+
if (isnan(get_float(pos)))
641639
{
642640
/* Replace NAN with zero */
643641
bzero(key, length);

storage/maria/ma_key.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,7 @@ MARIA_KEY *_ma_make_key(MARIA_HA *info, MARIA_KEY *int_key, uint keynr,
284284
{ /* Numerical column */
285285
if (type == HA_KEYTYPE_FLOAT)
286286
{
287-
float nr;
288-
float4get(nr,pos);
289-
if (isnan(nr))
287+
if (isnan(get_float(pos)))
290288
{
291289
/* Replace NAN with zero */
292290
bzero(key,length);

storage/myisam/mi_key.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ uint _mi_make_key(register MI_INFO *info, uint keynr, uchar *key,
158158
{ /* Numerical column */
159159
if (type == HA_KEYTYPE_FLOAT)
160160
{
161-
float nr;
162-
float4get(nr,pos);
163-
if (isnan(nr))
161+
if (isnan(get_float(pos)))
164162
{
165163
/* Replace NAN with zero */
166164
bzero(key,length);

0 commit comments

Comments
 (0)