mirror of
https://github.com/pybind/pybind11.git
synced 2025-02-22 16:39:29 +00:00
Cache direct converters in the generic type caster
This commit is contained in:
parent
cbbb7830f2
commit
ccc69f91f4
@ -157,7 +157,8 @@ inline void keep_alive_impl(handle nurse, handle patient);
|
|||||||
class type_caster_generic {
|
class type_caster_generic {
|
||||||
public:
|
public:
|
||||||
PYBIND11_NOINLINE type_caster_generic(const std::type_info &type_info)
|
PYBIND11_NOINLINE type_caster_generic(const std::type_info &type_info)
|
||||||
: typeinfo(get_type_info(type_info, false)), tindex(type_info) { }
|
: typeinfo(get_type_info(type_info, false)),
|
||||||
|
direct_conversions(get_internals().direct_conversions[std::type_index(type_info)]) { }
|
||||||
|
|
||||||
PYBIND11_NOINLINE bool load(handle src, bool convert) {
|
PYBIND11_NOINLINE bool load(handle src, bool convert) {
|
||||||
if (!src)
|
if (!src)
|
||||||
@ -297,21 +298,17 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
const type_info *typeinfo = nullptr;
|
const type_info *typeinfo = nullptr;
|
||||||
std::type_index tindex;
|
const std::vector<bool (*)(PyObject *, void *&)>& direct_conversions;
|
||||||
void *value = nullptr;
|
void *value = nullptr;
|
||||||
object temp;
|
object temp;
|
||||||
|
|
||||||
bool load_direct(handle src, bool convert) {
|
bool load_direct(handle src, bool convert) {
|
||||||
if (convert) {
|
if (convert) {
|
||||||
auto& direct = get_internals().direct_conversions;
|
for (auto& converter : direct_conversions) {
|
||||||
auto it = direct.find(tindex);
|
|
||||||
if (it != direct.end()) {
|
|
||||||
for (auto& converter : it->second) {
|
|
||||||
if (converter(src.ptr(), value))
|
if (converter(src.ptr(), value))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user