summaryrefslogtreecommitdiff
path: root/myisam/mi_open.c
diff options
context:
space:
mode:
Diffstat (limited to 'myisam/mi_open.c')
-rw-r--r--myisam/mi_open.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/myisam/mi_open.c b/myisam/mi_open.c
index aeacf81d90a..0da5ebabf40 100644
--- a/myisam/mi_open.c
+++ b/myisam/mi_open.c
@@ -559,28 +559,36 @@ err:
DBUG_RETURN (NULL);
} /* mi_open */
+
byte *mi_alloc_rec_buff(MI_INFO *info, ulong length, byte **buf)
{
uint extra;
+ uint32 old_length;
+ LINT_INIT(old_length);
- if (! *buf || length > mi_get_rec_buff_len(info, *buf))
+ if (! *buf || length > (old_length=mi_get_rec_buff_len(info, *buf)))
{
byte *newptr = *buf;
/* to simplify initial init of info->rec_buf in mi_open and mi_extra */
if (length == (ulong) -1)
+ {
length= max(info->s->base.pack_reclength+info->s->base.pack_bits,
info->s->base.max_key_length);
+ /* Avoid unnecessary realloc */
+ if (newptr && length == old_length)
+ return newptr;
+ }
extra= ((info->s->options & HA_OPTION_PACK_RECORD) ?
ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER)+MI_SPLIT_LENGTH+
MI_REC_BUFF_OFFSET : 0);
if (extra && newptr)
- newptr-=MI_REC_BUFF_OFFSET;
+ newptr-= MI_REC_BUFF_OFFSET;
if (!(newptr=(byte*) my_realloc((gptr)newptr, length+extra+8,
MYF(MY_ALLOW_ZERO_PTR))))
return newptr;
- *((uint *)newptr)=length;
+ *((uint32 *) newptr)= (uint32) length;
*buf= newptr+(extra ? MI_REC_BUFF_OFFSET : 0);
}
return *buf;