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
This commit is contained in:
parent
0b5cfd3496
commit
454ac64d19
|
@ -133,8 +133,8 @@ public:
|
||||||
virtual bool have_messages() const { return ! messages.empty(); };
|
virtual bool have_messages() const { return ! messages.empty(); };
|
||||||
virtual std::vector<Glib::ustring> get_messages() const { return messages; };
|
virtual std::vector<Glib::ustring> get_messages() const { return messages; };
|
||||||
virtual void clear_messages() { messages.clear(); };
|
virtual void clear_messages() { messages.clear(); };
|
||||||
void push_back_message( Glib::ustring msg ) { messages.push_back( msg ); };
|
void push_back_message(const Glib::ustring& msg) { messages.push_back(msg); };
|
||||||
void append_messages( const std::vector<Glib::ustring> msgs )
|
void append_messages(const std::vector<Glib::ustring>& msgs)
|
||||||
{ messages.insert( messages.end(), msgs.begin(), msgs.end() ); }
|
{ messages.insert( messages.end(), msgs.begin(), msgs.end() ); }
|
||||||
|
|
||||||
// Interface to return reference to the Partition object directly containing the
|
// Interface to return reference to the Partition object directly containing the
|
||||||
|
|
Loading…
Reference in New Issue