diff options
author | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2017-06-18 19:48:57 +0300 |
---|---|---|
committer | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2017-06-28 15:23:36 +0300 |
commit | 90038693903044bbbf7946ac128c3757ad33d7ba (patch) | |
tree | f3596c10eae1ed4d48ba5e4e6324ec5c63923aba | |
parent | b3171607e3e3024ea493c785831a7421a36fa7fe (diff) | |
download | mariadb-git-90038693903044bbbf7946ac128c3757ad33d7ba.tar.gz |
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.
-rw-r--r-- | include/my_sys.h | 20 | ||||
-rw-r--r-- | mysys/mf_iocache.c | 39 | ||||
-rw-r--r-- | sql/filesort.cc | 3 | ||||
-rw-r--r-- | storage/maria/ma_sort.c | 2 | ||||
-rw-r--r-- | storage/myisam/sort.c | 2 | ||||
-rw-r--r-- | unittest/sql/mf_iocache-t.cc | 2 |
6 files changed, 11 insertions, 57 deletions
diff --git a/include/my_sys.h b/include/my_sys.h index ed5a7200ec8..fb3e15b64a4 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -423,14 +423,6 @@ typedef struct st_io_cache /* Used when cacheing files */ 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 need mutex copying from append buffer to read buffer. */ @@ -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) { - 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) @@ -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) { - 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); @@ -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, my_off_t seek_offset, my_bool use_async_io, 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, IO_CACHE *write_cache, uint num_threads); diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c index 23f2d7984d3..0c2c1da354c 100644 --- a/mysys/mf_iocache.c +++ b/mysys/mf_iocache.c @@ -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; -/* - 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 init_functions(IO_CACHE* info) @@ -148,8 +120,6 @@ init_functions(IO_CACHE* info) DBUG_ASSERT(0); break; } - - setup_io_cache(info); } @@ -360,12 +330,7 @@ int init_slave_io_cache(IO_CACHE *master, IO_CACHE *slave) memcpy(slave->buffer, master->buffer, master->buffer_length); slave->read_pos= slave->buffer + (master->read_pos - 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) { IO_CACHE *p; @@ -924,8 +889,6 @@ void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare, read_cache->share= cshare; read_cache->read_function= _my_b_cache_read_r; - read_cache->current_pos= NULL; - read_cache->current_end= NULL; if (write_cache) { diff --git a/sql/filesort.cc b/sql/filesort.cc index 83c8442937e..2388dd759b5 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -1483,8 +1483,6 @@ int merge_many_buff(Sort_param *param, uchar *sort_buffer, if (flush_io_cache(to_file)) break; /* purecov: inspected */ 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; } cleanup: @@ -1492,7 +1490,6 @@ cleanup: if (to_file == t_file) { *t_file=t_file2; // Copy result file - setup_io_cache(t_file); } DBUG_RETURN(*maxbuffer >= MERGEBUFF2); /* Return 1 if interrupted */ diff --git a/storage/maria/ma_sort.c b/storage/maria/ma_sort.c index edd5650e07b..6e106976b70 100644 --- a/storage/maria/ma_sort.c +++ b/storage/maria/ma_sort.c @@ -896,8 +896,6 @@ cleanup: { DBUG_ASSERT(t_file2.type == WRITE_CACHE); *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 */ diff --git a/storage/myisam/sort.c b/storage/myisam/sort.c index 0d177072ec7..533f2cd2aa6 100644 --- a/storage/myisam/sort.c +++ b/storage/myisam/sort.c @@ -844,8 +844,6 @@ cleanup: { DBUG_ASSERT(t_file2.type == WRITE_CACHE); *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 */ diff --git a/unittest/sql/mf_iocache-t.cc b/unittest/sql/mf_iocache-t.cc index a7db7c58713..36860892508 100644 --- a/unittest/sql/mf_iocache-t.cc +++ b/unittest/sql/mf_iocache-t.cc @@ -93,7 +93,7 @@ IO_CACHE info; #define CACHE_SIZE 16384 #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 |