mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
maint(perf): Optimize Numpy constructor to remove copies by value. (#3183)
* maint(perf): Optimize Numpy Constructor with additional std::move * Add more moves
This commit is contained in:
parent
61ee923bb1
commit
ff590c1258
@ -478,11 +478,11 @@ public:
|
||||
|
||||
dtype(list names, list formats, list offsets, ssize_t itemsize) {
|
||||
dict args;
|
||||
args["names"] = names;
|
||||
args["formats"] = formats;
|
||||
args["offsets"] = offsets;
|
||||
args["names"] = std::move(names);
|
||||
args["formats"] = std::move(formats);
|
||||
args["offsets"] = std::move(offsets);
|
||||
args["itemsize"] = pybind11::int_(itemsize);
|
||||
m_ptr = from_args(args).release().ptr();
|
||||
m_ptr = from_args(std::move(args)).release().ptr();
|
||||
}
|
||||
|
||||
/// This is essentially the same as calling numpy.dtype(args) in Python.
|
||||
@ -560,7 +560,7 @@ private:
|
||||
formats.append(descr.format);
|
||||
offsets.append(descr.offset);
|
||||
}
|
||||
return dtype(names, formats, offsets, itemsize);
|
||||
return dtype(std::move(names), std::move(formats), std::move(offsets), itemsize);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1134,7 +1134,10 @@ inline PYBIND11_NOINLINE void register_structured_dtype(
|
||||
formats.append(field.descr);
|
||||
offsets.append(pybind11::int_(field.offset));
|
||||
}
|
||||
auto dtype_ptr = pybind11::dtype(names, formats, offsets, itemsize).release().ptr();
|
||||
auto dtype_ptr
|
||||
= pybind11::dtype(std::move(names), std::move(formats), std::move(offsets), itemsize)
|
||||
.release()
|
||||
.ptr();
|
||||
|
||||
// There is an existing bug in NumPy (as of v1.11): trailing bytes are
|
||||
// not encoded explicitly into the format string. This will supposedly
|
||||
|
Loading…
Reference in New Issue
Block a user