|
Packit |
6c4009 |
/* Copyright (c) 1997-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <nss.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This is from libc/db/hash/hash_func.c, hash3 is static there */
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* This is INCREDIBLY ugly, but fast. We break the string up into 8 byte
|
|
Packit |
6c4009 |
* units. On the first time through the loop we get the "leftover bytes"
|
|
Packit |
6c4009 |
* (strlen % 8). On every other iteration, we perform 8 HASHC's so we handle
|
|
Packit |
6c4009 |
* all 8 bytes. Essentially, this saves us 7 cmp & branch instructions. If
|
|
Packit |
6c4009 |
* this routine is heavily used enough, it's worth the ugly coding.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* OZ's original sdbm hash
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
uint32_t
|
|
Packit |
6c4009 |
__nss_hash (const void *keyarg, size_t len)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
const unsigned char *key;
|
|
Packit |
6c4009 |
size_t loop;
|
|
Packit |
6c4009 |
uint32_t h;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define HASHC h = *key++ + 65599 * h
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
h = 0;
|
|
Packit |
6c4009 |
key = keyarg;
|
|
Packit |
6c4009 |
if (len > 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
loop = (len + 8 - 1) >> 3;
|
|
Packit |
6c4009 |
switch (len & (8 - 1))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
case 0:
|
|
Packit |
6c4009 |
do
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
HASHC;
|
|
Packit |
6c4009 |
/* FALLTHROUGH */
|
|
Packit |
6c4009 |
case 7:
|
|
Packit |
6c4009 |
HASHC;
|
|
Packit |
6c4009 |
/* FALLTHROUGH */
|
|
Packit |
6c4009 |
case 6:
|
|
Packit |
6c4009 |
HASHC;
|
|
Packit |
6c4009 |
/* FALLTHROUGH */
|
|
Packit |
6c4009 |
case 5:
|
|
Packit |
6c4009 |
HASHC;
|
|
Packit |
6c4009 |
/* FALLTHROUGH */
|
|
Packit |
6c4009 |
case 4:
|
|
Packit |
6c4009 |
HASHC;
|
|
Packit |
6c4009 |
/* FALLTHROUGH */
|
|
Packit |
6c4009 |
case 3:
|
|
Packit |
6c4009 |
HASHC;
|
|
Packit |
6c4009 |
/* FALLTHROUGH */
|
|
Packit |
6c4009 |
case 2:
|
|
Packit |
6c4009 |
HASHC;
|
|
Packit |
6c4009 |
/* FALLTHROUGH */
|
|
Packit |
6c4009 |
case 1:
|
|
Packit |
6c4009 |
HASHC;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
while (--loop);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
return h;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
libc_hidden_def (__nss_hash)
|