Commit 90038693 authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru

Simplify IO_CACHE by removing current_pos and end_pos as self-references

These self references were previously used to avoid having to check the
IO_CACHE's type. However, a benchmark shows that on x86 5930k stock,
the type comparison is marginally faster than the double pointer dereference.
For 40 billion my_b_tell calls, the difference is .1 seconds in favor of performing the
type check. (Basically there is no measurable difference)

To prevent bugs from copying the structure using the equals(=) operator,
and having to do the bookkeeping manually, remove these "convenience"
variables.
parent b3171607
...@@ -422,14 +422,6 @@ typedef struct st_io_cache /* Used when cacheing files */ ...@@ -422,14 +422,6 @@ typedef struct st_io_cache /* Used when cacheing files */
/* The non-inclusive boundary of the valid write area */ /* The non-inclusive boundary of the valid write area */
uchar *write_end; uchar *write_end;
/*
Current_pos and current_end are convenience variables used by
my_b_tell() and other routines that need to know the current offset
current_pos points to &write_pos, and current_end to &write_end in a
WRITE_CACHE, and &read_pos and &read_end respectively otherwise
*/
uchar **current_pos, **current_end;
/* /*
The lock is for append buffer used in SEQ_READ_APPEND cache The lock is for append buffer used in SEQ_READ_APPEND cache
need mutex copying from append buffer to read buffer. need mutex copying from append buffer to read buffer.
...@@ -584,7 +576,11 @@ static inline size_t my_b_fill(IO_CACHE *info) ...@@ -584,7 +576,11 @@ static inline size_t my_b_fill(IO_CACHE *info)
static inline my_off_t my_b_tell(const IO_CACHE *info) static inline my_off_t my_b_tell(const IO_CACHE *info)
{ {
return info->pos_in_file + (*info->current_pos - info->request_pos); if (info->type == WRITE_CACHE) {
return info->pos_in_file + (info->write_pos - info->request_pos);
}
return info->pos_in_file + (info->read_pos - info->request_pos);
} }
static inline my_off_t my_b_write_tell(const IO_CACHE *info) static inline my_off_t my_b_write_tell(const IO_CACHE *info)
...@@ -609,7 +605,10 @@ static inline my_off_t my_b_get_pos_in_file(const IO_CACHE *info) ...@@ -609,7 +605,10 @@ static inline my_off_t my_b_get_pos_in_file(const IO_CACHE *info)
static inline size_t my_b_bytes_in_cache(const IO_CACHE *info) static inline size_t my_b_bytes_in_cache(const IO_CACHE *info)
{ {
return *info->current_end - *info->current_pos; if (info->type == WRITE_CACHE) {
return info->write_end - info->write_pos;
}
return info->read_end - info->read_pos;
} }
int my_b_copy_to_file(IO_CACHE *cache, FILE *file); int my_b_copy_to_file(IO_CACHE *cache, FILE *file);
...@@ -803,7 +802,6 @@ extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize, ...@@ -803,7 +802,6 @@ extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type, extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
my_off_t seek_offset, my_bool use_async_io, my_off_t seek_offset, my_bool use_async_io,
my_bool clear_cache); my_bool clear_cache);
extern void setup_io_cache(IO_CACHE* info);
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare, extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
IO_CACHE *write_cache, uint num_threads); IO_CACHE *write_cache, uint num_threads);
......
...@@ -74,34 +74,6 @@ int (*_my_b_encr_read)(IO_CACHE *info,uchar *Buffer,size_t Count)= 0; ...@@ -74,34 +74,6 @@ int (*_my_b_encr_read)(IO_CACHE *info,uchar *Buffer,size_t Count)= 0;
int (*_my_b_encr_write)(IO_CACHE *info,const uchar *Buffer,size_t Count)= 0; int (*_my_b_encr_write)(IO_CACHE *info,const uchar *Buffer,size_t Count)= 0;
/*
Setup internal pointers inside IO_CACHE
SYNOPSIS
setup_io_cache()
info IO_CACHE handler
NOTES
This is called on automatically on init or reinit of IO_CACHE
It must be called externally if one moves or copies an IO_CACHE
object.
*/
void setup_io_cache(IO_CACHE* info)
{
/* Ensure that my_b_tell() and my_b_bytes_in_cache works */
if (info->type == WRITE_CACHE)
{
info->current_pos= &info->write_pos;
info->current_end= &info->write_end;
}
else
{
info->current_pos= &info->read_pos;
info->current_end= &info->read_end;
}
}
static void static void
init_functions(IO_CACHE* info) init_functions(IO_CACHE* info)
...@@ -148,8 +120,6 @@ init_functions(IO_CACHE* info) ...@@ -148,8 +120,6 @@ init_functions(IO_CACHE* info)
DBUG_ASSERT(0); DBUG_ASSERT(0);
break; break;
} }
setup_io_cache(info);
} }
...@@ -360,12 +330,7 @@ int init_slave_io_cache(IO_CACHE *master, IO_CACHE *slave) ...@@ -360,12 +330,7 @@ int init_slave_io_cache(IO_CACHE *master, IO_CACHE *slave)
memcpy(slave->buffer, master->buffer, master->buffer_length); memcpy(slave->buffer, master->buffer, master->buffer_length);
slave->read_pos= slave->buffer + (master->read_pos - master->buffer); slave->read_pos= slave->buffer + (master->read_pos - master->buffer);
slave->read_end= slave->buffer + (master->read_end - master->buffer); slave->read_end= slave->buffer + (master->read_end - master->buffer);
DBUG_ASSERT(master->current_pos == &master->read_pos);
slave->current_pos= &slave->read_pos;
DBUG_ASSERT(master->current_end == &master->read_end);
slave->current_end= &slave->read_end;
if (master->next_file_user) if (master->next_file_user)
{ {
IO_CACHE *p; IO_CACHE *p;
...@@ -924,8 +889,6 @@ void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare, ...@@ -924,8 +889,6 @@ void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
read_cache->share= cshare; read_cache->share= cshare;
read_cache->read_function= _my_b_cache_read_r; read_cache->read_function= _my_b_cache_read_r;
read_cache->current_pos= NULL;
read_cache->current_end= NULL;
if (write_cache) if (write_cache)
{ {
......
...@@ -1483,8 +1483,6 @@ int merge_many_buff(Sort_param *param, uchar *sort_buffer, ...@@ -1483,8 +1483,6 @@ int merge_many_buff(Sort_param *param, uchar *sort_buffer,
if (flush_io_cache(to_file)) if (flush_io_cache(to_file))
break; /* purecov: inspected */ break; /* purecov: inspected */
temp=from_file; from_file=to_file; to_file=temp; temp=from_file; from_file=to_file; to_file=temp;
setup_io_cache(from_file);
setup_io_cache(to_file);
*maxbuffer= (uint) (lastbuff-buffpek)-1; *maxbuffer= (uint) (lastbuff-buffpek)-1;
} }
cleanup: cleanup:
...@@ -1492,7 +1490,6 @@ int merge_many_buff(Sort_param *param, uchar *sort_buffer, ...@@ -1492,7 +1490,6 @@ int merge_many_buff(Sort_param *param, uchar *sort_buffer,
if (to_file == t_file) if (to_file == t_file)
{ {
*t_file=t_file2; // Copy result file *t_file=t_file2; // Copy result file
setup_io_cache(t_file);
} }
DBUG_RETURN(*maxbuffer >= MERGEBUFF2); /* Return 1 if interrupted */ DBUG_RETURN(*maxbuffer >= MERGEBUFF2); /* Return 1 if interrupted */
......
...@@ -896,8 +896,6 @@ static int merge_many_buff(MARIA_SORT_PARAM *info, ha_keys keys, ...@@ -896,8 +896,6 @@ static int merge_many_buff(MARIA_SORT_PARAM *info, ha_keys keys,
{ {
DBUG_ASSERT(t_file2.type == WRITE_CACHE); DBUG_ASSERT(t_file2.type == WRITE_CACHE);
*t_file=t_file2; /* Copy result file */ *t_file=t_file2; /* Copy result file */
t_file->current_pos= &t_file->write_pos;
t_file->current_end= &t_file->write_end;
} }
DBUG_RETURN(*maxbuffer >= MERGEBUFF2); /* Return 1 if interrupted */ DBUG_RETURN(*maxbuffer >= MERGEBUFF2); /* Return 1 if interrupted */
......
...@@ -844,8 +844,6 @@ static int merge_many_buff(MI_SORT_PARAM *info, ha_keys keys, ...@@ -844,8 +844,6 @@ static int merge_many_buff(MI_SORT_PARAM *info, ha_keys keys,
{ {
DBUG_ASSERT(t_file2.type == WRITE_CACHE); DBUG_ASSERT(t_file2.type == WRITE_CACHE);
*t_file=t_file2; /* Copy result file */ *t_file=t_file2; /* Copy result file */
t_file->current_pos= &t_file->write_pos;
t_file->current_end= &t_file->write_end;
} }
DBUG_RETURN(*maxbuffer >= MERGEBUFF2); /* Return 1 if interrupted */ DBUG_RETURN(*maxbuffer >= MERGEBUFF2); /* Return 1 if interrupted */
......
...@@ -93,7 +93,7 @@ IO_CACHE info; ...@@ -93,7 +93,7 @@ IO_CACHE info;
#define CACHE_SIZE 16384 #define CACHE_SIZE 16384
#define INFO_TAIL ", pos_in_file = %llu, pos_in_mem = %lu", \ #define INFO_TAIL ", pos_in_file = %llu, pos_in_mem = %lu", \
info.pos_in_file, (ulong) (*info.current_pos - info.request_pos) info.pos_in_file, (ulong) ((info.type == READ_CACHE ? info.read_pos : info.write_pos) - info.request_pos)
#define FILL 0x5A #define FILL 0x5A
......
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