[gimp/wip/nielsdg/bye-bye-stock-id: 3/3] viewable: Use GET_PRIVATE() before precondition checks
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/nielsdg/bye-bye-stock-id: 3/3] viewable: Use GET_PRIVATE() before precondition checks
- Date: Tue, 12 May 2020 16:01:59 +0000 (UTC)
commit 7ac6f0a22e34e89ed58b3704404f355c933fdd49
Author: Niels De Graef <nielsdegraef gmail com>
Date: Tue May 12 17:56:31 2020 +0200
viewable: Use GET_PRIVATE() before precondition checks
`GET_PRIVATE()` expands to `gimp_viewable_get_instance_private()`, which
just returns an offset of the passed on pointer. As such, it's safe to
call this on any value (even NULL) and to put it at the top of the
function block, saving some lines.
app/core/gimpviewable.c | 36 +++++++++---------------------------
1 file changed, 9 insertions(+), 27 deletions(-)
---
diff --git a/app/core/gimpviewable.c b/app/core/gimpviewable.c
index 17ab8ca4d0..54583178ce 100644
--- a/app/core/gimpviewable.c
+++ b/app/core/gimpviewable.c
@@ -564,11 +564,10 @@ gimp_viewable_deserialize_property (GimpConfig *config,
void
gimp_viewable_invalidate_preview (GimpViewable *viewable)
{
- GimpViewablePrivate *private;
+ GimpViewablePrivate *private = GET_PRIVATE (viewable);
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
- private = GET_PRIVATE (viewable);
if (private->freeze_count == 0)
g_signal_emit (viewable, viewable_signals[INVALIDATE_PREVIEW], 0);
@@ -587,12 +586,10 @@ gimp_viewable_invalidate_preview (GimpViewable *viewable)
void
gimp_viewable_size_changed (GimpViewable *viewable)
{
- GimpViewablePrivate *private;
+ GimpViewablePrivate *private = GET_PRIVATE (viewable);
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
- private = GET_PRIVATE (viewable);
-
if (private->freeze_count == 0)
g_signal_emit (viewable, viewable_signals[SIZE_CHANGED], 0);
else
@@ -851,7 +848,7 @@ gimp_viewable_get_preview (GimpViewable *viewable,
gint width,
gint height)
{
- GimpViewablePrivate *private;
+ GimpViewablePrivate *private = GET_PRIVATE (viewable);
GimpViewableClass *viewable_class;
GimpTempBuf *temp_buf = NULL;
@@ -860,8 +857,6 @@ gimp_viewable_get_preview (GimpViewable *viewable,
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
- private = GET_PRIVATE (viewable);
-
if (G_UNLIKELY (context == NULL))
g_warning ("%s: context is NULL", G_STRFUNC);
@@ -1008,7 +1003,7 @@ gimp_viewable_get_pixbuf (GimpViewable *viewable,
gint width,
gint height)
{
- GimpViewablePrivate *private;
+ GimpViewablePrivate *private = GET_PRIVATE (viewable);
GimpViewableClass *viewable_class;
GdkPixbuf *pixbuf = NULL;
@@ -1017,8 +1012,6 @@ gimp_viewable_get_pixbuf (GimpViewable *viewable,
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
- private = GET_PRIVATE (viewable);
-
if (G_UNLIKELY (context == NULL))
g_warning ("%s: context is NULL", G_STRFUNC);
@@ -1217,12 +1210,10 @@ gimp_viewable_is_name_editable (GimpViewable *viewable)
const gchar *
gimp_viewable_get_icon_name (GimpViewable *viewable)
{
- GimpViewablePrivate *private;
+ GimpViewablePrivate *private = GET_PRIVATE (viewable);
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
- private = GET_PRIVATE (viewable);
-
if (private->icon_name)
return (const gchar *) private->icon_name;
@@ -1242,13 +1233,11 @@ void
gimp_viewable_set_icon_name (GimpViewable *viewable,
const gchar *icon_name)
{
- GimpViewablePrivate *private;
+ GimpViewablePrivate *private = GET_PRIVATE (viewable);
GimpViewableClass *viewable_class;
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
- private = GET_PRIVATE (viewable);
-
g_clear_pointer (&private->icon_name, g_free);
viewable_class = GIMP_VIEWABLE_GET_CLASS (viewable);
@@ -1268,12 +1257,10 @@ gimp_viewable_set_icon_name (GimpViewable *viewable,
void
gimp_viewable_preview_freeze (GimpViewable *viewable)
{
- GimpViewablePrivate *private;
+ GimpViewablePrivate *private = GET_PRIVATE (viewable);
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
- private = GET_PRIVATE (viewable);
-
private->freeze_count++;
if (private->freeze_count == 1)
@@ -1288,12 +1275,9 @@ gimp_viewable_preview_freeze (GimpViewable *viewable)
void
gimp_viewable_preview_thaw (GimpViewable *viewable)
{
- GimpViewablePrivate *private;
+ GimpViewablePrivate *private = GET_PRIVATE (viewable);
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
-
- private = GET_PRIVATE (viewable);
-
g_return_if_fail (private->freeze_count > 0);
private->freeze_count--;
@@ -1341,13 +1325,11 @@ void
gimp_viewable_set_parent (GimpViewable *viewable,
GimpViewable *parent)
{
- GimpViewablePrivate *private;
+ GimpViewablePrivate *private = GET_PRIVATE (viewable);
g_return_if_fail (GIMP_IS_VIEWABLE (viewable));
g_return_if_fail (parent == NULL || GIMP_IS_VIEWABLE (parent));
- private = GET_PRIVATE (viewable);
-
if (parent != private->parent)
{
private->parent = parent;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]