From 454ac64d1905ade9576cd09bb9ef5555d795c619 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sat, 23 Mar 2019 10:19:09 +0000 Subject: [PATCH] Pass message parameters by reference to 2 Partition methods (#788813) Note that this almost certainly has no performance benefit what so ever because the methods are implicitly defined as inline [1][2] and the compiler will have simply inlined the method bodies thus avoiding having to construct copies of the passed parameters. Do this anyway as constant objects are typically passed by reference [3]. Also C++'s std::vector::push_back() [4] takes a const reference parameter so update the kind of equivalent push_back_message() to take a const reference parameter too. [1] C++ reference / inline specifier https://en.cppreference.com/w/cpp/language/inline A function defined entirely inside a class/struct/union definition, whether it's a member function or a non-member friend function, is implicitly an inline function. [2] When should I write the keyword 'inline' for a function/method? https://stackoverflow.com/questions/1759300/when-should-i-write-the-keyword-inline-for-a-function-method/1759575#1759575 [3] How to pass objects to functions in C++? https://stackoverflow.com/questions/2139224/how-to-pass-objects-to-functions-in-c/2139254#2139254 [4] C++ reference / std::vector::push https://en.cppreference.com/w/cpp/container/vector/push_back void push_back(const T& value); Bug 788813 - gparted-0.30.0/include/Partition.h:137]: performance problem --- include/Partition.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Partition.h b/include/Partition.h index da2dac2b..87b103ca 100644 --- a/include/Partition.h +++ b/include/Partition.h @@ -133,8 +133,8 @@ public: virtual bool have_messages() const { return ! messages.empty(); }; virtual std::vector get_messages() const { return messages; }; virtual void clear_messages() { messages.clear(); }; - void push_back_message( Glib::ustring msg ) { messages.push_back( msg ); }; - void append_messages( const std::vector msgs ) + void push_back_message(const Glib::ustring& msg) { messages.push_back(msg); }; + void append_messages(const std::vector& msgs) { messages.insert( messages.end(), msgs.begin(), msgs.end() ); } // Interface to return reference to the Partition object directly containing the