mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 06:35:12 +00:00
chore: add a couple of moves in pybind11.h (#3941)
* Add missing std::moves in enum_base methods * Remove useless move * Add one more std::move in print * Further optimize print * Some more misc optimizations
This commit is contained in:
parent
dff6fa0554
commit
a8b3ff30f9
@ -1926,7 +1926,8 @@ struct enum_base {
|
||||
[](const object &arg) -> str {
|
||||
handle type = type::handle_of(arg);
|
||||
object type_name = type.attr("__name__");
|
||||
return pybind11::str("<{}.{}: {}>").format(type_name, enum_name(arg), int_(arg));
|
||||
return pybind11::str("<{}.{}: {}>")
|
||||
.format(std::move(type_name), enum_name(arg), int_(arg));
|
||||
},
|
||||
name("__repr__"),
|
||||
is_method(m_base));
|
||||
@ -1936,7 +1937,7 @@ struct enum_base {
|
||||
m_base.attr("__str__") = cpp_function(
|
||||
[](handle arg) -> str {
|
||||
object type_name = type::handle_of(arg).attr("__name__");
|
||||
return pybind11::str("{}.{}").format(type_name, enum_name(arg));
|
||||
return pybind11::str("{}.{}").format(std::move(type_name), enum_name(arg));
|
||||
},
|
||||
name("name"),
|
||||
is_method(m_base));
|
||||
@ -2576,8 +2577,8 @@ PYBIND11_NOINLINE void print(const tuple &args, const dict &kwargs) {
|
||||
for (size_t i = 0; i < args.size(); ++i) {
|
||||
strings[i] = str(args[i]);
|
||||
}
|
||||
auto sep = kwargs.contains("sep") ? kwargs["sep"] : cast(" ");
|
||||
auto line = sep.attr("join")(strings);
|
||||
auto sep = kwargs.contains("sep") ? kwargs["sep"] : str(" ");
|
||||
auto line = sep.attr("join")(std::move(strings));
|
||||
|
||||
object file;
|
||||
if (kwargs.contains("file")) {
|
||||
@ -2596,7 +2597,7 @@ PYBIND11_NOINLINE void print(const tuple &args, const dict &kwargs) {
|
||||
|
||||
auto write = file.attr("write");
|
||||
write(line);
|
||||
write(kwargs.contains("end") ? kwargs["end"] : cast("\n"));
|
||||
write(kwargs.contains("end") ? kwargs["end"] : str("\n"));
|
||||
|
||||
if (kwargs.contains("flush") && kwargs["flush"].cast<bool>()) {
|
||||
file.attr("flush")();
|
||||
@ -2639,7 +2640,7 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
|
||||
|
||||
function override = getattr(self, name, function());
|
||||
if (override.is_cpp_function()) {
|
||||
cache.insert(key);
|
||||
cache.insert(std::move(key));
|
||||
return function();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user