From 16d8367aae66039476b834a6926bdd251ac100ae Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 19 Mar 2014 09:57:09 +0100 Subject: [PATCH] List<>-style template wrapper over hash_filo --- sql/hash_filo.h | 13 +++++++++++++ sql/hostname.cc | 8 ++++---- sql/sql_acl.cc | 7 +++---- sql/sql_servers.cc | 1 - 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/sql/hash_filo.h b/sql/hash_filo.h index abba4824c9e..4c8c7575efc 100644 --- a/sql/hash_filo.h +++ b/sql/hash_filo.h @@ -199,4 +199,17 @@ public: } }; +template class Hash_filo: public hash_filo +{ +public: + Hash_filo(uint size_arg, uint key_offset_arg, uint key_length_arg, + my_hash_get_key get_key_arg, my_hash_free_key free_element_arg, + CHARSET_INFO *hash_charset_arg) : + hash_filo(size_arg, key_offset_arg, key_length_arg, + get_key_arg, free_element_arg, hash_charset_arg) {} + T* first() { return (T*)hash_filo::first(); } + T* last() { return (T*)hash_filo::last(); } + T* search(uchar* key, size_t len) { return (T*)hash_filo::search(key, len); } +}; + #endif diff --git a/sql/hostname.cc b/sql/hostname.cc index 8a4df816057..11cd16ac857 100644 --- a/sql/hostname.cc +++ b/sql/hostname.cc @@ -126,7 +126,7 @@ void Host_errors::aggregate(const Host_errors *errors) m_local+= errors->m_local; } -static hash_filo *hostname_cache; +static Hash_filo *hostname_cache; ulong host_cache_size; void hostname_cache_refresh() @@ -149,7 +149,7 @@ bool hostname_cache_init() Host_entry tmp; uint key_offset= (uint) ((char*) (&tmp.ip_key) - (char*) &tmp); - if (!(hostname_cache= new hash_filo(host_cache_size, + if (!(hostname_cache= new Hash_filo(host_cache_size, key_offset, HOST_ENTRY_KEY_SIZE, NULL, (my_hash_free_key) free, &my_charset_bin))) @@ -187,11 +187,11 @@ static void prepare_hostname_cache_key(const char *ip_string, } Host_entry *hostname_cache_first() -{ return (Host_entry *) hostname_cache->first(); } +{ return hostname_cache->first(); } static inline Host_entry *hostname_cache_search(const char *ip_key) { - return (Host_entry *) hostname_cache->search((uchar *) ip_key, 0); + return hostname_cache->search((uchar *) ip_key, 0); } static void add_hostname_impl(const char *ip_key, const char *hostname, diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 8d9989cd748..734be48d111 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -727,7 +727,7 @@ static bool initialized=0; static bool allow_all_hosts=1; static HASH acl_check_hosts, column_priv_hash, proc_priv_hash, func_priv_hash; static DYNAMIC_ARRAY acl_wild_hosts; -static hash_filo *acl_cache; +static Hash_filo *acl_cache; static uint grant_version=0; /* Version of priv tables. incremented by acl_load */ static ulong get_access(TABLE *form,uint fieldnr, uint *next_field=0); static bool check_is_role(TABLE *form); @@ -924,7 +924,7 @@ my_bool acl_init(bool dont_read_acl_tables) my_bool return_val; DBUG_ENTER("acl_init"); - acl_cache= new hash_filo(ACL_CACHE_SIZE, 0, 0, + acl_cache= new Hash_filo(ACL_CACHE_SIZE, 0, 0, (my_hash_get_key) acl_entry_get_key, (my_hash_free_key) free, &my_charset_utf8_bin); @@ -2182,8 +2182,7 @@ ulong acl_get(const char *host, const char *ip, key_length= (size_t) (end-key); mysql_mutex_lock(&acl_cache->lock); - if (!db_is_pattern && (entry=(acl_entry*) acl_cache->search((uchar*) key, - key_length))) + if (!db_is_pattern && (entry=acl_cache->search((uchar*) key, key_length))) { db_access=entry->access; mysql_mutex_unlock(&acl_cache->lock); diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index cf96297391c..637ee78e314 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -38,7 +38,6 @@ #include "unireg.h" #include "sql_base.h" // close_mysql_tables #include "records.h" // init_read_record, end_read_record -#include "hash_filo.h" #include #include #include "sp_head.h"