|
4 | 4 | #include "sentry/logging/state.h" |
5 | 5 | #include "sentry/sentry_options.h" |
6 | 6 | #include "sentry/sentry_sdk.h" |
| 7 | +#include "sentry/util/hash.h" |
7 | 8 |
|
8 | 9 | #include <godot_cpp/classes/engine.hpp> |
9 | 10 | #include <godot_cpp/classes/resource_loader.hpp> |
@@ -162,36 +163,6 @@ Vector<SentryEvent::StackFrame> _extract_error_stack_frames_from_backtraces( |
162 | 163 | return frames; |
163 | 164 | } |
164 | 165 |
|
165 | | -// FNV-1a hash - portable hash implementation that doesn't rely on std::hash<*>. |
166 | | -// See https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash |
167 | | -inline size_t _fnv1a_hash(const char *p_data, size_t p_len) { |
168 | | - // FNV-1a constants for 64-bit or 32-bit depending on platform |
169 | | - // See table: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV_hash_parameters |
170 | | - constexpr size_t FNV_OFFSET_BASIS = sizeof(size_t) == 8 ? 14695981039346656037ULL : 2166136261U; |
171 | | - constexpr size_t FNV_PRIME = sizeof(size_t) == 8 ? 1099511628211ULL : 16777619U; |
172 | | - |
173 | | - size_t hash = FNV_OFFSET_BASIS; |
174 | | - for (size_t i = 0; i < p_len; i++) { |
175 | | - hash ^= static_cast<uint64_t>(static_cast<unsigned char>(p_data[i])); |
176 | | - hash *= FNV_PRIME; |
177 | | - } |
178 | | - return hash; |
179 | | -} |
180 | | - |
181 | | -inline size_t _hash(std::string_view p_value) { |
182 | | - return _fnv1a_hash(p_value.data(), p_value.size()); |
183 | | -} |
184 | | - |
185 | | -inline size_t _hash(int p_value) { |
186 | | - return p_value; |
187 | | -} |
188 | | - |
189 | | -template <typename T> |
190 | | -inline void _hash_combine(std::size_t &p_hash, T p_value) { |
191 | | - // NOTE: Hash combining technique, originally from boost. |
192 | | - p_hash ^= _hash(p_value) + 0x9e3779b9 + (p_hash << 6) + (p_hash >> 2); |
193 | | -} |
194 | | - |
195 | 166 | String _strip_invisible(const String &p_text) { |
196 | 167 | String result; |
197 | 168 |
|
@@ -240,9 +211,9 @@ std::size_t SentryGodotLogger::ErrorKeyHash::operator()(const ErrorKey &p_key) c |
240 | 211 | std::string_view message_sv{ message_cstr.get_data() }; |
241 | 212 | std::string_view filename_sv{ filename_cstr.get_data() }; |
242 | 213 |
|
243 | | - size_t hash_value = _hash(message_sv); |
244 | | - _hash_combine(hash_value, filename_sv); |
245 | | - _hash_combine(hash_value, p_key.line); |
| 214 | + size_t hash_value = sentry::util::hash(message_sv); |
| 215 | + sentry::util::hash_combine(hash_value, filename_sv); |
| 216 | + sentry::util::hash_combine(hash_value, p_key.line); |
246 | 217 | return hash_value; |
247 | 218 | } |
248 | 219 |
|
|
0 commit comments