Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
84fa8230
Commit
84fa8230
authored
Feb 20, 2017
by
antirez
Browse files
Use locale agnostic tolower() in dict.c hash function.
parent
05ea8c61
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/Makefile
View file @
84fa8230
...
...
@@ -204,7 +204,7 @@ $(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
$(REDIS_LD)
-o
$@
$^
$(FINAL_LIBS)
dict-benchmark
:
dict.c zmalloc.c sds.c
$(REDIS_CC)
$(FINAL_CFLAGS)
dict.c zmalloc.c sds.c
-D
DICT_BENCHMARK_MAIN
-o
dict-benchmark
$(REDIS_CC)
$(FINAL_CFLAGS)
dict.c zmalloc.c sds.c
siphash.c
-D
DICT_BENCHMARK_MAIN
-o
dict-benchmark
# Because the jemalloc.h header is generated as a part of the jemalloc build,
# building it should complete before building any other object. Instead of
...
...
src/dict.c
View file @
84fa8230
...
...
@@ -1109,7 +1109,7 @@ void dictGetStats(char *buf, size_t bufsize, dict *d) {
#include "sds.h"
u
nsigned
in
t
hashCallback
(
const
void
*
key
)
{
u
int64_
t
hashCallback
(
const
void
*
key
)
{
return
dictGenHashFunction
((
unsigned
char
*
)
key
,
sdslen
((
char
*
)
key
));
}
...
...
src/siphash.c
View file @
84fa8230
...
...
@@ -40,6 +40,16 @@
#include <string.h>
#include <ctype.h>
/* Fast tolower() alike function that does not care about locale
* but just returns a-z insetad of A-Z. */
int
siptlw
(
int
c
)
{
if
(
c
>=
'A'
&&
c
<=
'Z'
)
{
return
c
+
(
'a'
-
'A'
);
}
else
{
return
c
;
}
}
/* Test of the CPU is Little Endian and supports not aligned accesses.
* Two interesting conditions to speedup the function that happen to be
* in most of x86 servers. */
...
...
@@ -70,14 +80,14 @@
#endif
#define U8TO64_LE_NOCASE(p) \
(((uint64_t)(
tolower
((p)[0]))) | \
((uint64_t)(
tolower
((p)[1])) << 8) | \
((uint64_t)(
tolower
((p)[2])) << 16) | \
((uint64_t)(
tolower
((p)[3])) << 24) | \
((uint64_t)(
tolower
((p)[4])) << 32) | \
((uint64_t)(
tolower
((p)[5])) << 40) | \
((uint64_t)(
tolower
((p)[6])) << 48) | \
((uint64_t)(
tolower
((p)[7])) << 56))
(((uint64_t)(
siptlw
((p)[0]))) | \
((uint64_t)(
siptlw
((p)[1])) << 8) | \
((uint64_t)(
siptlw
((p)[2])) << 16) | \
((uint64_t)(
siptlw
((p)[3])) << 24) | \
((uint64_t)(
siptlw
((p)[4])) << 32) | \
((uint64_t)(
siptlw
((p)[5])) << 40) | \
((uint64_t)(
siptlw
((p)[6])) << 48) | \
((uint64_t)(
siptlw
((p)[7])) << 56))
#define SIPROUND \
do { \
...
...
@@ -192,13 +202,13 @@ uint64_t siphash_nocase(const uint8_t *in, const size_t inlen, const uint8_t *k)
}
switch
(
left
)
{
case
7
:
b
|=
((
uint64_t
)
tolower
(
in
[
6
]))
<<
48
;
case
6
:
b
|=
((
uint64_t
)
tolower
(
in
[
5
]))
<<
40
;
case
5
:
b
|=
((
uint64_t
)
tolower
(
in
[
4
]))
<<
32
;
case
4
:
b
|=
((
uint64_t
)
tolower
(
in
[
3
]))
<<
24
;
case
3
:
b
|=
((
uint64_t
)
tolower
(
in
[
2
]))
<<
16
;
case
2
:
b
|=
((
uint64_t
)
tolower
(
in
[
1
]))
<<
8
;
case
1
:
b
|=
((
uint64_t
)
tolower
(
in
[
0
]));
break
;
case
7
:
b
|=
((
uint64_t
)
siptlw
(
in
[
6
]))
<<
48
;
case
6
:
b
|=
((
uint64_t
)
siptlw
(
in
[
5
]))
<<
40
;
case
5
:
b
|=
((
uint64_t
)
siptlw
(
in
[
4
]))
<<
32
;
case
4
:
b
|=
((
uint64_t
)
siptlw
(
in
[
3
]))
<<
24
;
case
3
:
b
|=
((
uint64_t
)
siptlw
(
in
[
2
]))
<<
16
;
case
2
:
b
|=
((
uint64_t
)
siptlw
(
in
[
1
]))
<<
8
;
case
1
:
b
|=
((
uint64_t
)
siptlw
(
in
[
0
]));
break
;
case
0
:
break
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment