From ca5e16f6583662857ab1bb48f1646f50cda8448e Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Thu, 21 Apr 2022 11:13:35 -0400 Subject: [PATCH] python: avoid some unnecessary object copies. --- src/python/corrade/containers.cpp | 4 ++-- src/python/magnum/math.matrix.h | 2 +- src/python/magnum/math.vector.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/python/corrade/containers.cpp b/src/python/corrade/containers.cpp index 51f9282..fd485a2 100644 --- a/src/python/corrade/containers.cpp +++ b/src/python/corrade/containers.cpp @@ -100,7 +100,7 @@ template void arrayView(py::class_, Containers .def(py::init(), "Default constructor") /* Buffer protocol */ - .def(py::init([](py::buffer other) { + .def(py::init([](const py::buffer& other) { /* GCC 4.8 otherwise loudly complains about missing initializers */ Py_buffer buffer{nullptr, nullptr, 0, 0, 0, 0, nullptr, nullptr, nullptr, nullptr, nullptr}; if(PyObject_GetBuffer(other.ptr(), &buffer, (std::is_const::value ? 0 : PyBUF_WRITABLE)) != 0) @@ -316,7 +316,7 @@ template void stridedArrayView(py::class_::value ? 0 : PyBUF_WRITABLE)) != 0) diff --git a/src/python/magnum/math.matrix.h b/src/python/magnum/math.matrix.h index 0f70098..6a26103 100644 --- a/src/python/magnum/math.matrix.h +++ b/src/python/magnum/math.matrix.h @@ -105,7 +105,7 @@ template void everyRectangularMatrixBuffer(py::class_ void everyVectorBuffer(py::class_& /* Buffer protocol. If not present, implicit conversion from numpy arrays of non-default types somehow doesn't work. There's also the other part in vectorBuffer(). */ - .def(py::init([](py::buffer other) { + .def(py::init([](const py::buffer& other) { /* GCC 4.8 otherwise loudly complains about missing initializers */ Py_buffer buffer{nullptr, nullptr, 0, 0, 0, 0, nullptr, nullptr, nullptr, nullptr, nullptr}; if(PyObject_GetBuffer(other.ptr(), &buffer, PyBUF_FORMAT|PyBUF_STRIDES) != 0) @@ -297,7 +297,7 @@ template void vector(py::module_& m, py::class_& c) { /* this should be handled by the x/y/z/w/r/g/b/a properties instead */ else CORRADE_INTERNAL_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ }, "Vector swizzle") - .def("__setattr__", [](T& self, py::str nameO, py::object valueO) { + .def("__setattr__", [](T& self, const py::str& nameO, const py::object& valueO) { std::string name = py::cast(nameO); /* If the name is just one character, this is better handled by dedicated properties (and if not, it'll provide a better