Commit | Line | Data |
---|---|---|
cd4fb1b2 SM |
1 | /* Things needed for both reading and writing DWARF indices. |
2 | ||
42a4f53d | 3 | Copyright (C) 1994-2019 Free Software Foundation, Inc. |
cd4fb1b2 SM |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "defs.h" | |
d55e5aa6 TT |
21 | |
22 | /* Local non-gdb includes. */ | |
cd4fb1b2 SM |
23 | #include "dwarf-index-common.h" |
24 | ||
25 | /* See dwarf-index-common.h. */ | |
26 | ||
27 | hashval_t | |
28 | mapped_index_string_hash (int index_version, const void *p) | |
29 | { | |
30 | const unsigned char *str = (const unsigned char *) p; | |
31 | hashval_t r = 0; | |
32 | unsigned char c; | |
33 | ||
34 | while ((c = *str++) != 0) | |
35 | { | |
36 | if (index_version >= 5) | |
37 | c = tolower (c); | |
38 | r = r * 67 + c - 113; | |
39 | } | |
40 | ||
41 | return r; | |
42 | } | |
43 | ||
44 | /* See dwarf-index-common.h. */ | |
45 | ||
46 | uint32_t | |
47 | dwarf5_djb_hash (const char *str_) | |
48 | { | |
49 | const unsigned char *str = (const unsigned char *) str_; | |
50 | ||
51 | /* Note: tolower here ignores UTF-8, which isn't fully compliant. | |
52 | See http://dwarfstd.org/ShowIssue.php?issue=161027.1. */ | |
53 | ||
54 | uint32_t hash = 5381; | |
55 | while (int c = *str++) | |
56 | hash = hash * 33 + tolower (c); | |
57 | return hash; | |
58 | } |