[vte] table: Remove unnecessary null checks



commit 35e071e687e0f9bfed5adc7117e2c2d4cd3237a9
Author: Christian Persch <chpe src gnome org>
Date:   Tue Nov 21 18:36:48 2017 +0100

    table: Remove unnecessary null checks
    
    We always pass non-null out parameters here, so remove
    the unnecessary checks.

 src/matcher.cc |    6 ++++--
 src/matcher.hh |   14 +++++++++-----
 src/table.cc   |   33 +++++++++++++--------------------
 src/table.hh   |    6 ++++--
 4 files changed, 30 insertions(+), 29 deletions(-)
---
diff --git a/src/matcher.cc b/src/matcher.cc
index 38ae150..f8028b8 100644
--- a/src/matcher.cc
+++ b/src/matcher.cc
@@ -178,8 +178,10 @@ _vte_matcher_free(struct _vte_matcher *matcher)
 /* Check if a string matches a sequence the matcher knows about. */
 const char *
 _vte_matcher_match(struct _vte_matcher *matcher,
-                  const gunichar *pattern, gssize length,
-                  const char **res, const gunichar **consumed,
+                  const gunichar *pattern,
+                   gssize length,
+                  const char **res,
+                   const gunichar **consumed,
                   GValueArray **array)
 {
        if (G_UNLIKELY (array != NULL && matcher->free_params != NULL)) {
diff --git a/src/matcher.hh b/src/matcher.hh
index 145ac28..4b088c7 100644
--- a/src/matcher.hh
+++ b/src/matcher.hh
@@ -31,9 +31,11 @@ struct _vte_matcher_impl {
 
 typedef struct _vte_matcher_impl *(*_vte_matcher_create_func)(void);
 typedef const char *(*_vte_matcher_match_func)(struct _vte_matcher_impl *impl,
-               const gunichar *pattern, gssize length,
-               const char **res, const gunichar **consumed,
-               GValueArray **array);
+                                               const gunichar *pattern,
+                                               gssize length,
+                                               const char **res,
+                                               const gunichar **consumed,
+                                               GValueArray **array);
 typedef void (*_vte_matcher_add_func)(struct _vte_matcher_impl *impl,
                const char *pattern, gssize length,
                const char *result);
@@ -55,8 +57,10 @@ void _vte_matcher_free(struct _vte_matcher *matcher);
 
 /* Check if a string matches a sequence the matcher knows about. */
 const char *_vte_matcher_match(struct _vte_matcher *matcher,
-                              const gunichar *pattern, gssize length,
-                              const char **res, const gunichar **consumed,
+                              const gunichar *pattern,
+                               gssize length,
+                              const char **res,
+                               const gunichar **consumed,
                               GValueArray **array);
 
 /* Dump out the contents of a matcher, mainly for debugging. */
diff --git a/src/table.cc b/src/table.cc
index 0f61898..c9bddd9 100644
--- a/src/table.cc
+++ b/src/table.cc
@@ -399,9 +399,12 @@ _vte_table_add(struct _vte_table *table,
 /* Match a string in a subtree. */
 static const char *
 _vte_table_matchi(struct _vte_table *table,
-                 const gunichar *candidate, gssize length,
-                 const char **res, const gunichar **consumed,
-                 unsigned char **original, gssize *original_length,
+                 const gunichar *candidate,
+                  gssize length,
+                 const char **res,
+                  const gunichar **consumed,
+                 unsigned char **original,
+                  gssize *original_length,
                  struct _vte_table_arginfo_head *params)
 {
        int i = 0;
@@ -588,14 +591,13 @@ _vte_table_extract_string(GValueArray **array,
 /* Check if a string matches something in the tree. */
 const char *
 _vte_table_match(struct _vte_table *table,
-                const gunichar *candidate, gssize length,
-                const char **res, const gunichar **consumed,
+                const gunichar *candidate,
+                 gssize length,
+                const char **res,
+                 const gunichar **consumed,
                 GValueArray **array)
 {
        struct _vte_table *head;
-       const gunichar *dummy_consumed;
-       const char *dummy_res;
-       GValueArray *dummy_array;
        const char *ret;
        unsigned char *original, *p;
        gssize original_length;
@@ -603,19 +605,10 @@ _vte_table_match(struct _vte_table *table,
        struct _vte_table_arginfo_head params;
        struct _vte_table_arginfo *arginfo;
 
-       /* Clean up extracted parameters. */
-       if (G_UNLIKELY (res == NULL)) {
-               res = &dummy_res;
-       }
+        g_assert_nonnull(res);
+        g_assert_nonnull(consumed);
        *res = NULL;
-       if (G_UNLIKELY (consumed == NULL)) {
-               consumed = &dummy_consumed;
-       }
        *consumed = candidate;
-       if (G_UNLIKELY (array == NULL)) {
-               dummy_array = NULL;
-               array = &dummy_array;
-       }
 
        /* Provide a fast path for the usual "not a sequence" cases. */
        if (G_LIKELY (length == 0 || candidate == NULL)) {
@@ -663,7 +656,7 @@ _vte_table_match(struct _vte_table *table,
        *res = ret;
 
        /* If we got a match, extract the parameters. */
-       if (ret != NULL && ret[0] != '\0' && array != &dummy_array) {
+       if (ret != NULL && ret[0] != '\0' && array != nullptr) {
                g_assert(original != NULL);
                p = original;
                arginfo = _vte_table_arginfo_head_reverse (&params);
diff --git a/src/table.hh b/src/table.hh
index 57ce7a2..8f80137 100644
--- a/src/table.hh
+++ b/src/table.hh
@@ -37,8 +37,10 @@ void _vte_table_add(struct _vte_table *table,
 
 /* Check if a string matches something in the tree. */
 const char *_vte_table_match(struct _vte_table *table,
-                            const gunichar *pattern, gssize length,
-                            const char **res, const gunichar **consumed,
+                            const gunichar *pattern,
+                             gssize length,
+                            const char **res,
+                             const gunichar **consumed,
                             GValueArray **array);
 /* Dump out the contents of a tree. */
 void _vte_table_print(struct _vte_table *table);


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