mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-11 08:03:55 +00:00
chore: optimize dictionary access in strip_padding numpy (#3994)
* emplace field descriptors * reserve sufficient capacity * remove std::move * properly iterate through dict * make handle casting more explicit * Revert to old dict api
This commit is contained in:
parent
918892b97e
commit
e2dcd95407
@ -641,10 +641,14 @@ private:
|
||||
pybind11::str name;
|
||||
object format;
|
||||
pybind11::int_ offset;
|
||||
field_descr(pybind11::str &&name, object &&format, pybind11::int_ &&offset)
|
||||
: name{std::move(name)}, format{std::move(format)}, offset{std::move(offset)} {};
|
||||
};
|
||||
auto field_dict = attr("fields").cast<dict>();
|
||||
std::vector<field_descr> field_descriptors;
|
||||
field_descriptors.reserve(field_dict.size());
|
||||
|
||||
for (auto field : attr("fields").attr("items")()) {
|
||||
for (auto field : field_dict.attr("items")()) {
|
||||
auto spec = field.cast<tuple>();
|
||||
auto name = spec[0].cast<pybind11::str>();
|
||||
auto spec_fo = spec[1].cast<tuple>();
|
||||
@ -653,8 +657,8 @@ private:
|
||||
if ((len(name) == 0u) && format.kind() == 'V') {
|
||||
continue;
|
||||
}
|
||||
field_descriptors.push_back(
|
||||
{(pybind11::str) name, format.strip_padding(format.itemsize()), offset});
|
||||
field_descriptors.emplace_back(
|
||||
std::move(name), format.strip_padding(format.itemsize()), std::move(offset));
|
||||
}
|
||||
|
||||
std::sort(field_descriptors.begin(),
|
||||
|
Loading…
Reference in New Issue
Block a user