[gtksourceview] buffer: use g_set_object() in set_language()



commit e7bf63ed6c83d74f22a9a1010b8f77cdc0cca002
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Jun 12 17:23:09 2016 +0200

    buffer: use g_set_object() in set_language()
    
    To simplify the code.

 gtksourceview/gtksourcebuffer.c |   15 +++------------
 1 files changed, 3 insertions(+), 12 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 2ae2cc2..7988144 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -1734,7 +1734,7 @@ gtk_source_buffer_set_language (GtkSourceBuffer   *buffer,
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
        g_return_if_fail (GTK_SOURCE_IS_LANGUAGE (language) || language == NULL);
 
-       if (buffer->priv->language == language)
+       if (!g_set_object (&buffer->priv->language, language))
        {
                return;
        }
@@ -1747,26 +1747,17 @@ gtk_source_buffer_set_language (GtkSourceBuffer   *buffer,
                buffer->priv->highlight_engine = NULL;
        }
 
-       if (buffer->priv->language != NULL)
-       {
-               g_object_unref (buffer->priv->language);
-       }
-
-       buffer->priv->language = language;
-
        if (language != NULL)
        {
-               g_object_ref (language);
-
                /* get a new engine */
                buffer->priv->highlight_engine = _gtk_source_language_create_engine (language);
 
-               if (buffer->priv->highlight_engine)
+               if (buffer->priv->highlight_engine != NULL)
                {
                        _gtk_source_engine_attach_buffer (buffer->priv->highlight_engine,
                                                          GTK_TEXT_BUFFER (buffer));
 
-                       if (buffer->priv->style_scheme)
+                       if (buffer->priv->style_scheme != NULL)
                        {
                                _gtk_source_engine_set_style_scheme (buffer->priv->highlight_engine,
                                                                     buffer->priv->style_scheme);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]