Skip to content

Commit d2332f3

Browse files
author
Steinar H. Gunderson
committed
Bug #25997748: MIGRATE FROM HASH TO STD::UNORDERED_MAP [patch 5, noclose]
Migrate the audit_log plugin's HASH instances to std::unordered_map. Change-Id: I40637f479b5704a7ab92cdae970fe427945af48b
1 parent 447d0f4 commit d2332f3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

include/map_helpers.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,36 +97,39 @@ using unique_ptr_free = std::unique_ptr<T, Free_deleter>;
9797
class Collation_hasher
9898
{
9999
public:
100-
explicit Collation_hasher(CHARSET_INFO *cs_arg) : cs(cs_arg) {}
100+
explicit Collation_hasher(const CHARSET_INFO *cs_arg)
101+
: cs(cs_arg), hash_sort(cs->coll->hash_sort) {}
101102

102103
size_t operator() (const std::string &s) const
103104
{
104105
ulong nr1= 1, nr2= 4;
105-
cs->coll->hash_sort(
106-
cs, pointer_cast<const uchar *>(s.data()), s.size(), &nr1, &nr2);
106+
hash_sort(cs, pointer_cast<const uchar *>(s.data()), s.size(), &nr1, &nr2);
107107
return nr1;
108108
}
109109

110110
private:
111-
CHARSET_INFO *cs;
111+
const CHARSET_INFO *cs;
112+
decltype(cs->coll->hash_sort) hash_sort;
112113
};
113114

114115
/** A KeyEqual that compares std::strings according to a MySQL collation. */
115116
class Collation_key_equal
116117
{
117118
public:
118-
explicit Collation_key_equal(CHARSET_INFO *cs_arg) : cs(cs_arg) {}
119+
explicit Collation_key_equal(const CHARSET_INFO *cs_arg)
120+
: cs(cs_arg), strnncollsp(cs->coll->strnncollsp) {}
119121

120122
size_t operator() (const std::string &a, const std::string &b) const
121123
{
122-
return cs->coll->strnncollsp(
124+
return strnncollsp(
123125
cs,
124126
pointer_cast<const uchar *>(a.data()), a.size(),
125127
pointer_cast<const uchar *>(b.data()), b.size()) == 0;
126128
}
127129

128130
private:
129-
CHARSET_INFO *cs;
131+
const CHARSET_INFO *cs;
132+
decltype(cs->coll->strnncollsp) strnncollsp;
130133
};
131134

132135
/**
@@ -161,7 +164,7 @@ class collation_unordered_map
161164
Malloc_allocator<std::pair<const Key, Value>>>
162165
{
163166
public:
164-
collation_unordered_map(CHARSET_INFO *cs, PSI_memory_key psi_key)
167+
collation_unordered_map(const CHARSET_INFO *cs, PSI_memory_key psi_key)
165168
: std::unordered_map<Key, Value, Collation_hasher, Collation_key_equal,
166169
Malloc_allocator<std::pair<const Key, Value>>>
167170
(/*bucket_count=*/ 10, Collation_hasher(cs), Collation_key_equal(cs),

0 commit comments

Comments
 (0)