From a9af48e9fc0b6bf91b272516dc8ec485b4faf7f3 Mon Sep 17 00:00:00 2001 From: unknown <bar@mysql.com> Date: Mon, 28 Nov 2005 12:41:44 +0400 Subject: [PATCH] item.cc, item.h: Fixing Item_param::safe_charset_converter to do less "new"s. sql/item.h: Fixing Item_param::safe_charset_converter to do less "new"s. sql/item.cc: Fixing Item_param::safe_charset_converter to do less "new"s. --- sql/item.cc | 26 ++++++++++---------------- sql/item.h | 4 ++++ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index 1767f9d97c1..0e45b8f2259 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -700,23 +700,15 @@ Item *Item_param::safe_charset_converter(CHARSET_INFO *tocs) { if (const_item()) { - Item_string *conv; uint cnv_errors; - char buf[MAX_FIELD_WIDTH]; - String tmp(buf, sizeof(buf), &my_charset_bin); - String cstr, *ostr= val_str(&tmp); - /* - As safe_charset_converter is not executed for - a parameter bound to NULL, ostr should never be 0. - */ - cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &cnv_errors); - if (cnv_errors || !(conv= new Item_string(cstr.ptr(), cstr.length(), - cstr.charset(), - collation.derivation))) - return NULL; - conv->str_value.copy(); - conv->str_value.mark_as_const(); - return conv; + String *ostr= val_str(&cnvstr); + cnvitem->str_value.copy(ostr->ptr(), ostr->length(), + ostr->charset(), tocs, &cnv_errors); + if (cnv_errors) + return NULL; + cnvitem->str_value.mark_as_const(); + cnvitem->max_length= cnvitem->str_value.numchars() * tocs->mbmaxlen; + return cnvitem; } return NULL; } @@ -2098,6 +2090,8 @@ Item_param::Item_param(unsigned pos_in_query_arg) : value is set. */ maybe_null= 1; + cnvitem= new Item_string("", 0, &my_charset_bin, DERIVATION_COERCIBLE); + cnvstr.set(cnvbuf, sizeof(cnvbuf), &my_charset_bin); } diff --git a/sql/item.h b/sql/item.h index 8bc659c3060..2b3a1ab3edb 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1075,7 +1075,11 @@ class Item_null_result :public Item_null class Item_param :public Item { + char cnvbuf[MAX_FIELD_WIDTH]; + String cnvstr; + Item *cnvitem; public: + enum enum_item_param_state { NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE, -- 2.30.9