The underlying set functions in gtk+ typically test if the value of the
property will really change, and they return quickly if it won't.
gtk_widget_set_sensitive() does so, and so do most (probably all)
functions that set a property. When the value really changes, the call
takes much more time, because a notify signal is emitted.
Conclusion: Even if the value won't change, you gain very little, or
possibly nothing, by first calling the corresponding get function.
When it comes to the question of good style, I prefer the shorter
version with an unconditional call to the set function.
I can't resist the temptation to mention another kind of unnecessary
test that I see quite often in C++ code:
MyType* var = 0;
if (...) var = new MyType();
.....
if (var) delete var;
"if (var)" is unnecessary. The delete operator repeats that test. It
does nothing when applied to a null pointer.
Kjell
2013-09-08 12:42, Jonas Platte skrev:
Hello, I've got a simple question: In gtkmm, when I want to set a
boolean property of any object, like a widget, and I don't know it's
current state, should I first check if the state isn't how I want it
to be, or should I always call set? For example, in the case I want a
widget to get insensitive, would I write:
if(widget.get_sensitive()) widget.set_sensitive(false);
or only
widget.set_sensitive(false);
And if it doesn't have a significant influence on the performance,
which one would you consider the better style?
Thanks,
Jonas
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list