[glib] GString: Avoid some repeated parameter checking



commit 23229bfd0cbd2588402835758238e36407814148
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Sep 7 10:35:13 2015 -0400

    GString: Avoid some repeated parameter checking
    
    Many of the append and prepend variants are just thin wrappers
    around another one. Remove parameter checking in the wrapper
    for these cases. The wrapped function is checking them anyway.

 glib/gstring.c |   20 +-------------------
 1 files changed, 1 insertions(+), 19 deletions(-)
---
diff --git a/glib/gstring.c b/glib/gstring.c
index 05c66d2..155b426 100644
--- a/glib/gstring.c
+++ b/glib/gstring.c
@@ -445,7 +445,7 @@ g_string_insert_len (GString     *string,
    * since ">=" and "<=" are only valid when val really is a substring.
    * In practice, it will work on modern archs.
    */
-  if (val >= string->str && val <= string->str + string->len)
+  if (G_UNLIKELY (val >= string->str && val <= string->str + string->len))
     {
       gsize offset = val - string->str;
       gsize precount = 0;
@@ -593,9 +593,6 @@ GString *
 g_string_append (GString     *string,
                  const gchar *val)
 {
-  g_return_val_if_fail (string != NULL, NULL);
-  g_return_val_if_fail (val != NULL, string);
-
   return g_string_insert_len (string, -1, val, -1);
 }
 
@@ -620,9 +617,6 @@ g_string_append_len (GString     *string,
                      const gchar *val,
                      gssize       len)
 {
-  g_return_val_if_fail (string != NULL, NULL);
-  g_return_val_if_fail (len == 0 || val != NULL, string);
-
   return g_string_insert_len (string, -1, val, len);
 }
 
@@ -679,9 +673,6 @@ GString *
 g_string_prepend (GString     *string,
                   const gchar *val)
 {
-  g_return_val_if_fail (string != NULL, NULL);
-  g_return_val_if_fail (val != NULL, string);
-
   return g_string_insert_len (string, 0, val, -1);
 }
 
@@ -706,9 +697,6 @@ g_string_prepend_len (GString     *string,
                       const gchar *val,
                       gssize       len)
 {
-  g_return_val_if_fail (string != NULL, NULL);
-  g_return_val_if_fail (val != NULL, string);
-
   return g_string_insert_len (string, 0, val, len);
 }
 
@@ -766,12 +754,6 @@ g_string_insert (GString     *string,
                  gssize       pos,
                  const gchar *val)
 {
-  g_return_val_if_fail (string != NULL, NULL);
-  g_return_val_if_fail (val != NULL, string);
-
-  if (pos >= 0)
-    g_return_val_if_fail (pos <= string->len, string);
-
   return g_string_insert_len (string, pos, val, -1);
 }
 


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