Skip to content

Commit 82455a4

Browse files
authored
Minor opt to cache tuple casting (#3894)
1 parent 2a7cb00 commit 82455a4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/pybind11/numpy.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,9 @@ class dtype : public object {
647647
for (auto field : attr("fields").attr("items")()) {
648648
auto spec = field.cast<tuple>();
649649
auto name = spec[0].cast<pybind11::str>();
650-
auto format = spec[1].cast<tuple>()[0].cast<dtype>();
651-
auto offset = spec[1].cast<tuple>()[1].cast<pybind11::int_>();
650+
auto spec_fo = spec[1].cast<tuple>();
651+
auto format = spec_fo[0].cast<dtype>();
652+
auto offset = spec_fo[1].cast<pybind11::int_>();
652653
if ((len(name) == 0u) && format.kind() == 'V') {
653654
continue;
654655
}

0 commit comments

Comments
 (0)