Skip to content

Commit ac286c9

Browse files
authored
internals: optimize std::unordered_map internals with noexcept (#5960)
1 parent ccb7129 commit ac286c9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/pybind11/detail/internals.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ inline bool same_type(const std::type_info &lhs, const std::type_info &rhs) {
191191
}
192192

193193
struct type_hash {
194-
size_t operator()(const std::type_index &t) const {
194+
size_t operator()(const std::type_index &t) const noexcept {
195195
size_t hash = 5381;
196196
const char *ptr = t.name();
197197
while (auto c = static_cast<unsigned char>(*ptr++)) {
@@ -202,7 +202,7 @@ struct type_hash {
202202
};
203203

204204
struct type_equal_to {
205-
bool operator()(const std::type_index &lhs, const std::type_index &rhs) const {
205+
bool operator()(const std::type_index &lhs, const std::type_index &rhs) const noexcept {
206206
return lhs.name() == rhs.name() || std::strcmp(lhs.name(), rhs.name()) == 0;
207207
}
208208
};
@@ -218,7 +218,7 @@ template <typename value_type>
218218
using type_map = std::unordered_map<std::type_index, value_type, type_hash, type_equal_to>;
219219

220220
struct override_hash {
221-
size_t operator()(const std::pair<const PyObject *, const char *> &v) const {
221+
size_t operator()(const std::pair<const PyObject *, const char *> &v) const noexcept {
222222
size_t value = std::hash<const void *>()(v.first);
223223
value ^= std::hash<const void *>()(v.second) + 0x9e3779b9 + (value << 6) + (value >> 2);
224224
return value;

0 commit comments

Comments
 (0)