Skip to content

Commit c89e927

Browse files
committed
Clean up Item_uint() & Item_int()
- Removed val_str() and print() as these are handled by Item_int() - Use local StringBuffer for Item_int::print() to avoid mallocs
1 parent 5e76e23 commit c89e927

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

include/my_global.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,8 @@ inline unsigned long long my_double2ulonglong(double d)
796796
#define LONGLONG_MIN((long long) 0x8000000000000000LL)
797797
#define LONGLONG_MAX((long long) 0x7FFFFFFFFFFFFFFFLL)
798798
#endif
799+
/* Max length needed for a buffer to hold a longlong or ulonglong + end \0 */
800+
#define LONGLONG_BUFFER_SIZE 21
799801

800802
#if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
801803
/* First check for ANSI C99 definition: */

sql/item.cc

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3626,9 +3626,10 @@ String *Item_int::val_str(String *str)
36263626

36273627
void Item_int::print(String *str, enum_query_type query_type)
36283628
{
3629+
StringBuffer<LONGLONG_BUFFER_SIZE> buf;
36293630
// my_charset_bin is good enough for numbers
3630-
str_value.set_int(value, unsigned_flag, &my_charset_bin);
3631-
str->append(str_value);
3631+
buf.set_int(value, unsigned_flag, &my_charset_bin);
3632+
str->append(buf);
36323633
}
36333634

36343635

@@ -3654,21 +3655,6 @@ Item_uint::Item_uint(THD *thd, const char *str_arg, longlong i, uint length):
36543655
}
36553656

36563657

3657-
String *Item_uint::val_str(String *str)
3658-
{
3659-
str->set((ulonglong) value, collation.collation);
3660-
return str;
3661-
}
3662-
3663-
3664-
void Item_uint::print(String *str, enum_query_type query_type)
3665-
{
3666-
// latin1 is good enough for numbers
3667-
str_value.set((ulonglong) value, default_charset());
3668-
str->append(str_value);
3669-
}
3670-
3671-
36723658
Item_decimal::Item_decimal(THD *thd, const char *str_arg, size_t length,
36733659
CHARSET_INFO *charset):
36743660
Item_num(thd)

sql/item.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4238,9 +4238,7 @@ class Item_uint :public Item_int
42384238
Item_uint(THD *thd, ulonglong i): Item_int(thd, i, 10) {}
42394239
Item_uint(THD *thd, const char *str_arg, longlong i, uint length);
42404240
double val_real() { return ulonglong2double((ulonglong)value); }
4241-
String *val_str(String*);
42424241
Item *clone_item(THD *thd);
4243-
virtual void print(String *str, enum_query_type query_type);
42444242
Item *neg(THD *thd);
42454243
uint decimal_precision() const { return max_length; }
42464244
Item *get_copy(THD *thd)

0 commit comments

Comments
 (0)