[template-glib] expr: use internal value for NOP



commit a584ab18a5182667a53f323d259830dad868359e
Author: Christian Hergert <chergert redhat com>
Date:   Thu May 5 15:21:06 2022 -0700

    expr: use internal value for NOP
    
    We don't need to allocate these, so long as reference counting is correct
    they never get freed and we can just re-use the same instance as a constant
    sort of cheap hack.

 src/tmpl-expr.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/src/tmpl-expr.c b/src/tmpl-expr.c
index d040f81..3903802 100644
--- a/src/tmpl-expr.c
+++ b/src/tmpl-expr.c
@@ -158,7 +158,9 @@ tmpl_expr_destroy (TmplExpr *self)
       break;
 
     case TMPL_EXPR_NOP:
-      break;
+      /* This should never happen,
+       * but just log it if it does */
+      g_return_if_reached ();
 
     default:
       g_assert_not_reached ();
@@ -436,5 +438,6 @@ tmpl_expr_new_anon_call (TmplExpr *func,
 TmplExpr *
 tmpl_expr_new_nop (void)
 {
-  return (TmplExpr *)tmpl_expr_new (TMPL_EXPR_NOP);
+  static TmplExpr interned = { .any.type = TMPL_EXPR_NOP, .any.ref_count = 1 };
+  return tmpl_expr_ref (&interned);
 }


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