Skip to content

Commit 65e53c8

Browse files
committed
cleanup: Field_blob::get_ptr()
and declare few other Field getters to be 'const'
1 parent 9a3ec79 commit 65e53c8

File tree

5 files changed

+30
-36
lines changed

5 files changed

+30
-36
lines changed

sql/field.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7883,7 +7883,7 @@ void Field_blob::store_length(uchar *i_ptr, uint i_packlength, uint32 i_number)
78837883
}
78847884

78857885

7886-
uint32 Field_blob::get_length(const uchar *pos, uint packlength_arg)
7886+
uint32 Field_blob::get_length(const uchar *pos, uint packlength_arg) const
78877887
{
78887888
return (uint32)read_lowendian(pos, packlength_arg);
78897889
}
@@ -7898,8 +7898,7 @@ int Field_blob::copy_value(Field_blob *from)
78987898
DBUG_ASSERT(field_charset == from->charset());
78997899
int rc= 0;
79007900
uint32 length= from->get_length();
7901-
uchar *data;
7902-
from->get_ptr(&data);
7901+
uchar *data= from->get_ptr();
79037902
if (packlength < from->packlength)
79047903
{
79057904
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)
81468145
bzero(buff, image_length);
81478146
return image_length;
81488147
}
8149-
get_ptr(&blob);
8148+
blob= get_ptr();
81508149
gobj= Geometry::construct(&buffer, (char*) blob, blob_length);
81518150
if (!gobj || gobj->get_mbr(&mbr, &dummy))
81528151
bzero(buff, image_length);
@@ -8161,7 +8160,7 @@ uint Field_blob::get_key_image(uchar *buff,uint length, imagetype type_arg)
81618160
}
81628161
#endif /*HAVE_SPATIAL*/
81638162

8164-
get_ptr(&blob);
8163+
blob= get_ptr();
81658164
uint local_char_length= length / field_charset->mbmaxlen;
81668165
local_char_length= my_charpos(field_charset, blob, blob + blob_length,
81678166
local_char_length);
@@ -8320,7 +8319,7 @@ uchar *Field_blob::pack(uchar *to, const uchar *from, uint max_length)
83208319
*/
83218320
if (length > 0)
83228321
{
8323-
get_ptr((uchar**) &from);
8322+
from= get_ptr();
83248323
memcpy(to+packlength, from,length);
83258324
}
83268325
ptr=save; // Restore org row pointer

sql/field.h

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ class Field: public Value_source
12651265
virtual uint max_packed_col_length(uint max_length)
12661266
{ return max_length;}
12671267

1268-
uint offset(uchar *record)
1268+
uint offset(uchar *record) const
12691269
{
12701270
return (uint) (ptr - record);
12711271
}
@@ -3266,30 +3266,29 @@ class Field_blob :public Field_longstr {
32663266
{
32673267
store_length(ptr, packlength, number);
32683268
}
3269-
inline uint32 get_length(uint row_offset= 0)
3269+
inline uint32 get_length(uint row_offset= 0) const
32703270
{ return get_length(ptr+row_offset, this->packlength); }
3271-
uint32 get_length(const uchar *ptr, uint packlength);
3272-
uint32 get_length(const uchar *ptr_arg)
3271+
uint32 get_length(const uchar *ptr, uint packlength) const;
3272+
uint32 get_length(const uchar *ptr_arg) const
32733273
{ return get_length(ptr_arg, this->packlength); }
3274-
inline void get_ptr(uchar **str)
3275-
{
3276-
memcpy(str, ptr+packlength, sizeof(uchar*));
3277-
}
3278-
inline void get_ptr(uchar **str, uint row_offset)
3279-
{
3280-
memcpy(str, ptr+packlength+row_offset, sizeof(char*));
3281-
}
3274+
inline uchar *get_ptr() const { return get_ptr(0); }
3275+
inline uchar *get_ptr(my_ptrdiff_t row_offset) const
3276+
{
3277+
uchar *s;
3278+
memcpy(&s, ptr + packlength + row_offset, sizeof(uchar*));
3279+
return s;
3280+
}
32823281
inline void set_ptr(uchar *length, uchar *data)
3283-
{
3284-
memcpy(ptr,length,packlength);
3285-
memcpy(ptr+packlength, &data,sizeof(char*));
3286-
}
3282+
{
3283+
memcpy(ptr,length,packlength);
3284+
memcpy(ptr+packlength, &data,sizeof(char*));
3285+
}
32873286
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data)
3288-
{
3289-
uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
3290-
store_length(ptr_ofs, packlength, length);
3291-
memcpy(ptr_ofs+packlength, &data, sizeof(char*));
3292-
}
3287+
{
3288+
uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
3289+
store_length(ptr_ofs, packlength, length);
3290+
memcpy(ptr_ofs+packlength, &data, sizeof(char*));
3291+
}
32933292
inline void set_ptr(uint32 length, uchar *data)
32943293
{
32953294
set_ptr_offset(0, length, data);
@@ -3303,8 +3302,7 @@ class Field_blob :public Field_longstr {
33033302
void sql_type(String &str) const;
33043303
inline bool copy()
33053304
{
3306-
uchar *tmp;
3307-
get_ptr(&tmp);
3305+
uchar *tmp= get_ptr();
33083306
if (value.copy((char*) tmp, get_length(), charset()))
33093307
{
33103308
Field_blob::reset();
@@ -3320,7 +3318,7 @@ class Field_blob :public Field_longstr {
33203318
uint packed_col_length(const uchar *col_ptr, uint length);
33213319
uint max_packed_col_length(uint max_length);
33223320
void free() { value.free(); }
3323-
inline void clear_temporary() { bzero((uchar*) &value,sizeof(value)); }
3321+
inline void clear_temporary() { bzero((uchar*) &value, sizeof(value)); }
33243322
uint size_of() const { return sizeof(*this); }
33253323
bool has_charset(void) const
33263324
{ return charset() == &my_charset_bin ? FALSE : TRUE; }

sql/sql_insert.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,9 +3126,7 @@ static void free_delayed_insert_blobs(register TABLE *table)
31263126
{
31273127
if ((*ptr)->flags & BLOB_FLAG)
31283128
{
3129-
uchar *str;
3130-
((Field_blob *) (*ptr))->get_ptr(&str);
3131-
my_free(str);
3129+
my_free(((Field_blob *) (*ptr))->get_ptr());
31323130
((Field_blob *) (*ptr))->reset();
31333131
}
31343132
}

sql/sql_join_cache.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ uint JOIN_CACHE::write_record_data(uchar * link, bool *is_full)
13041304
uint blob_len= blob_field->get_length();
13051305
(*copy_ptr)->blob_length= blob_len;
13061306
len+= blob_len;
1307-
blob_field->get_ptr(&(*copy_ptr)->str);
1307+
(*copy_ptr)->str= blob_field->get_ptr();
13081308
}
13091309
}
13101310
}

storage/archive/ha_archive.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,7 @@ unsigned int ha_archive::pack_row_v1(uchar *record)
383383
uint32 length= ((Field_blob *) table->field[*blob])->get_length();
384384
if (length)
385385
{
386-
uchar *data_ptr;
387-
((Field_blob *) table->field[*blob])->get_ptr(&data_ptr);
386+
uchar *data_ptr= ((Field_blob *) table->field[*blob])->get_ptr();
388387
memcpy(pos, data_ptr, length);
389388
pos+= length;
390389
}

0 commit comments

Comments
 (0)