Commit 65e53c8b authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: Field_blob::get_ptr()

and declare few other Field getters to be 'const'
parent 9a3ec79b
...@@ -7883,7 +7883,7 @@ void Field_blob::store_length(uchar *i_ptr, uint i_packlength, uint32 i_number) ...@@ -7883,7 +7883,7 @@ void Field_blob::store_length(uchar *i_ptr, uint i_packlength, uint32 i_number)
} }
uint32 Field_blob::get_length(const uchar *pos, uint packlength_arg) uint32 Field_blob::get_length(const uchar *pos, uint packlength_arg) const
{ {
return (uint32)read_lowendian(pos, packlength_arg); return (uint32)read_lowendian(pos, packlength_arg);
} }
...@@ -7898,8 +7898,7 @@ int Field_blob::copy_value(Field_blob *from) ...@@ -7898,8 +7898,7 @@ int Field_blob::copy_value(Field_blob *from)
DBUG_ASSERT(field_charset == from->charset()); DBUG_ASSERT(field_charset == from->charset());
int rc= 0; int rc= 0;
uint32 length= from->get_length(); uint32 length= from->get_length();
uchar *data; uchar *data= from->get_ptr();
from->get_ptr(&data);
if (packlength < from->packlength) if (packlength < from->packlength)
{ {
set_if_smaller(length, Field_blob::max_data_length()); set_if_smaller(length, Field_blob::max_data_length());
...@@ -8146,7 +8145,7 @@ uint Field_blob::get_key_image(uchar *buff,uint length, imagetype type_arg) ...@@ -8146,7 +8145,7 @@ uint Field_blob::get_key_image(uchar *buff,uint length, imagetype type_arg)
bzero(buff, image_length); bzero(buff, image_length);
return image_length; return image_length;
} }
get_ptr(&blob); blob= get_ptr();
gobj= Geometry::construct(&buffer, (char*) blob, blob_length); gobj= Geometry::construct(&buffer, (char*) blob, blob_length);
if (!gobj || gobj->get_mbr(&mbr, &dummy)) if (!gobj || gobj->get_mbr(&mbr, &dummy))
bzero(buff, image_length); bzero(buff, image_length);
...@@ -8161,7 +8160,7 @@ uint Field_blob::get_key_image(uchar *buff,uint length, imagetype type_arg) ...@@ -8161,7 +8160,7 @@ uint Field_blob::get_key_image(uchar *buff,uint length, imagetype type_arg)
} }
#endif /*HAVE_SPATIAL*/ #endif /*HAVE_SPATIAL*/
get_ptr(&blob); blob= get_ptr();
uint local_char_length= length / field_charset->mbmaxlen; uint local_char_length= length / field_charset->mbmaxlen;
local_char_length= my_charpos(field_charset, blob, blob + blob_length, local_char_length= my_charpos(field_charset, blob, blob + blob_length,
local_char_length); local_char_length);
...@@ -8320,7 +8319,7 @@ uchar *Field_blob::pack(uchar *to, const uchar *from, uint max_length) ...@@ -8320,7 +8319,7 @@ uchar *Field_blob::pack(uchar *to, const uchar *from, uint max_length)
*/ */
if (length > 0) if (length > 0)
{ {
get_ptr((uchar**) &from); from= get_ptr();
memcpy(to+packlength, from,length); memcpy(to+packlength, from,length);
} }
ptr=save; // Restore org row pointer ptr=save; // Restore org row pointer
......
...@@ -1265,7 +1265,7 @@ class Field: public Value_source ...@@ -1265,7 +1265,7 @@ class Field: public Value_source
virtual uint max_packed_col_length(uint max_length) virtual uint max_packed_col_length(uint max_length)
{ return max_length;} { return max_length;}
uint offset(uchar *record) uint offset(uchar *record) const
{ {
return (uint) (ptr - record); return (uint) (ptr - record);
} }
...@@ -3266,30 +3266,29 @@ class Field_blob :public Field_longstr { ...@@ -3266,30 +3266,29 @@ class Field_blob :public Field_longstr {
{ {
store_length(ptr, packlength, number); store_length(ptr, packlength, number);
} }
inline uint32 get_length(uint row_offset= 0) inline uint32 get_length(uint row_offset= 0) const
{ return get_length(ptr+row_offset, this->packlength); } { return get_length(ptr+row_offset, this->packlength); }
uint32 get_length(const uchar *ptr, uint packlength); uint32 get_length(const uchar *ptr, uint packlength) const;
uint32 get_length(const uchar *ptr_arg) uint32 get_length(const uchar *ptr_arg) const
{ return get_length(ptr_arg, this->packlength); } { return get_length(ptr_arg, this->packlength); }
inline void get_ptr(uchar **str) inline uchar *get_ptr() const { return get_ptr(0); }
{ inline uchar *get_ptr(my_ptrdiff_t row_offset) const
memcpy(str, ptr+packlength, sizeof(uchar*)); {
} uchar *s;
inline void get_ptr(uchar **str, uint row_offset) memcpy(&s, ptr + packlength + row_offset, sizeof(uchar*));
{ return s;
memcpy(str, ptr+packlength+row_offset, sizeof(char*)); }
}
inline void set_ptr(uchar *length, uchar *data) inline void set_ptr(uchar *length, uchar *data)
{ {
memcpy(ptr,length,packlength); memcpy(ptr,length,packlength);
memcpy(ptr+packlength, &data,sizeof(char*)); memcpy(ptr+packlength, &data,sizeof(char*));
} }
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data) void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data)
{ {
uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*); uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
store_length(ptr_ofs, packlength, length); store_length(ptr_ofs, packlength, length);
memcpy(ptr_ofs+packlength, &data, sizeof(char*)); memcpy(ptr_ofs+packlength, &data, sizeof(char*));
} }
inline void set_ptr(uint32 length, uchar *data) inline void set_ptr(uint32 length, uchar *data)
{ {
set_ptr_offset(0, length, data); set_ptr_offset(0, length, data);
...@@ -3303,8 +3302,7 @@ class Field_blob :public Field_longstr { ...@@ -3303,8 +3302,7 @@ class Field_blob :public Field_longstr {
void sql_type(String &str) const; void sql_type(String &str) const;
inline bool copy() inline bool copy()
{ {
uchar *tmp; uchar *tmp= get_ptr();
get_ptr(&tmp);
if (value.copy((char*) tmp, get_length(), charset())) if (value.copy((char*) tmp, get_length(), charset()))
{ {
Field_blob::reset(); Field_blob::reset();
...@@ -3320,7 +3318,7 @@ class Field_blob :public Field_longstr { ...@@ -3320,7 +3318,7 @@ class Field_blob :public Field_longstr {
uint packed_col_length(const uchar *col_ptr, uint length); uint packed_col_length(const uchar *col_ptr, uint length);
uint max_packed_col_length(uint max_length); uint max_packed_col_length(uint max_length);
void free() { value.free(); } void free() { value.free(); }
inline void clear_temporary() { bzero((uchar*) &value,sizeof(value)); } inline void clear_temporary() { bzero((uchar*) &value, sizeof(value)); }
uint size_of() const { return sizeof(*this); } uint size_of() const { return sizeof(*this); }
bool has_charset(void) const bool has_charset(void) const
{ return charset() == &my_charset_bin ? FALSE : TRUE; } { return charset() == &my_charset_bin ? FALSE : TRUE; }
......
...@@ -3126,9 +3126,7 @@ static void free_delayed_insert_blobs(register TABLE *table) ...@@ -3126,9 +3126,7 @@ static void free_delayed_insert_blobs(register TABLE *table)
{ {
if ((*ptr)->flags & BLOB_FLAG) if ((*ptr)->flags & BLOB_FLAG)
{ {
uchar *str; my_free(((Field_blob *) (*ptr))->get_ptr());
((Field_blob *) (*ptr))->get_ptr(&str);
my_free(str);
((Field_blob *) (*ptr))->reset(); ((Field_blob *) (*ptr))->reset();
} }
} }
......
...@@ -1304,7 +1304,7 @@ uint JOIN_CACHE::write_record_data(uchar * link, bool *is_full) ...@@ -1304,7 +1304,7 @@ uint JOIN_CACHE::write_record_data(uchar * link, bool *is_full)
uint blob_len= blob_field->get_length(); uint blob_len= blob_field->get_length();
(*copy_ptr)->blob_length= blob_len; (*copy_ptr)->blob_length= blob_len;
len+= blob_len; len+= blob_len;
blob_field->get_ptr(&(*copy_ptr)->str); (*copy_ptr)->str= blob_field->get_ptr();
} }
} }
} }
......
...@@ -383,8 +383,7 @@ unsigned int ha_archive::pack_row_v1(uchar *record) ...@@ -383,8 +383,7 @@ unsigned int ha_archive::pack_row_v1(uchar *record)
uint32 length= ((Field_blob *) table->field[*blob])->get_length(); uint32 length= ((Field_blob *) table->field[*blob])->get_length();
if (length) if (length)
{ {
uchar *data_ptr; uchar *data_ptr= ((Field_blob *) table->field[*blob])->get_ptr();
((Field_blob *) table->field[*blob])->get_ptr(&data_ptr);
memcpy(pos, data_ptr, length); memcpy(pos, data_ptr, length);
pos+= length; pos+= length;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment