diff --git a/libgnucash/engine/gnc-lot.c b/libgnucash/engine/gnc-lot.c index d1b411782a..a8eaf79025 100644 --- a/libgnucash/engine/gnc-lot.c +++ b/libgnucash/engine/gnc-lot.c @@ -86,6 +86,9 @@ typedef struct GNCLotPrivate /* List of splits that belong to this lot. */ SplitList *splits; + char *title; + char *notes; + GncInvoice *cached_invoice; /* Handy cached value to indicate if lot is closed. */ /* If value is negative, then the cache is invalid. */ @@ -103,6 +106,9 @@ typedef struct GNCLotPrivate /* ============================================================= */ +static char* +is_unset = "unset"; + /* GObject Initialization */ G_DEFINE_TYPE_WITH_PRIVATE(GNCLot, gnc_lot, QOF_TYPE_INSTANCE) @@ -116,6 +122,8 @@ gnc_lot_init(GNCLot* lot) priv->splits = NULL; priv->cached_invoice = NULL; priv->is_closed = LOT_CLOSED_UNKNOWN; + priv->title = is_unset; + priv->notes = is_unset; priv->marker = 0; } @@ -295,6 +303,14 @@ gnc_lot_free(GNCLot* lot) if (priv->account && !qof_instance_get_destroying(priv->account)) xaccAccountRemoveLot (priv->account, lot); + if (priv->notes != is_unset) + g_free (priv->notes); + + if (priv->title != is_unset) + g_free (priv->title); + + priv->notes = NULL; + priv->title = NULL; priv->account = NULL; priv->is_closed = TRUE; /* qof_instance_release (&lot->inst); */ @@ -439,30 +455,46 @@ gint gnc_lot_count_splits (const GNCLot *lot) const char * gnc_lot_get_title (const GNCLot *lot) { - GValue v = G_VALUE_INIT; + GNCLotPrivate* priv; if (!lot) return NULL; - qof_instance_get_kvp (QOF_INSTANCE (lot), &v, 1, "title"); - if (G_VALUE_HOLDS_STRING (&v)) - return g_value_get_string (&v); - return NULL; + priv = GET_PRIVATE (lot); + if (priv->title == is_unset) + { + GNCLotPrivate* priv = GET_PRIVATE (lot); + GValue v = G_VALUE_INIT; + qof_instance_get_kvp (QOF_INSTANCE (lot), &v, 1, "title"); + priv->title = G_VALUE_HOLDS_STRING (&v) ? g_value_dup_string (&v) : NULL; + g_value_unset (&v); + } + return priv->title; } const char * gnc_lot_get_notes (const GNCLot *lot) { - GValue v = G_VALUE_INIT; + GNCLotPrivate* priv; if (!lot) return NULL; - qof_instance_get_kvp (QOF_INSTANCE (lot), &v, 1, "notes"); - if (G_VALUE_HOLDS_STRING (&v)) - return g_value_get_string (&v); - return NULL; + priv = GET_PRIVATE (lot); + if (priv->notes == is_unset) + { + GValue v = G_VALUE_INIT; + qof_instance_get_kvp (QOF_INSTANCE (lot), &v, 1, "notes"); + priv->notes = G_VALUE_HOLDS_STRING (&v) ? g_value_dup_string (&v) : NULL; + g_value_unset (&v); + } + return priv->notes; } void gnc_lot_set_title (GNCLot *lot, const char *str) { GValue v = G_VALUE_INIT; + GNCLotPrivate* priv; if (!lot) return; + priv = GET_PRIVATE (lot); + if (priv->title != is_unset) + g_free (priv->title); + qof_begin_edit(QOF_INSTANCE(lot)); g_value_init (&v, G_TYPE_STRING); g_value_set_string (&v, str); @@ -476,7 +508,11 @@ void gnc_lot_set_notes (GNCLot *lot, const char *str) { GValue v = G_VALUE_INIT; + GNCLotPrivate* priv; if (!lot) return; + priv = GET_PRIVATE (lot); + if (priv->notes != is_unset) + g_free (priv->notes); qof_begin_edit(QOF_INSTANCE(lot)); g_value_init (&v, G_TYPE_STRING); g_value_set_string (&v, str);