gnucash stable: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Tue Nov 4 18:55:43 EST 2025
Updated via https://github.com/Gnucash/gnucash/commit/7bdf31f9 (commit)
via https://github.com/Gnucash/gnucash/commit/2119fceb (commit)
from https://github.com/Gnucash/gnucash/commit/2dfdb0ba (commit)
commit 7bdf31f9d38b712de95a7413017e5437f4a15283
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Nov 2 22:05:44 2025 +0800
[gnc-date.cpp] gnc_g_date_new_today calls gnc_gdate_set_today
instead of vice-versa.
- avoids malloc/free in gnc_gdate_set_today
- avoids unnecessary dmy->julian->dmy(*) conversion
(*) the GDate is typically used by gdate_to_time64 which performs a
julian->dmy conversion, and this is now avoided
diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index d3851857d5..0f46cfcf87 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -1230,20 +1230,17 @@ GDate time64_to_gdate (time64 t)
GDate* gnc_g_date_new_today ()
{
- GncDate gncd;
- auto ymd = gncd.year_month_day();
- auto month = static_cast<GDateMonth>(ymd.month);
- auto result = g_date_new_dmy (ymd.day, month, ymd.year);
- g_assert(g_date_valid (result));
- return result;
+ GDate* rv = g_date_new ();
+ gnc_gdate_set_today (rv);
+ return rv;
}
void
gnc_gdate_set_today (GDate* gd)
{
- GDate *today = gnc_g_date_new_today ();
- g_date_set_julian (gd, g_date_get_julian (today));
- g_date_free (today);
+ g_return_if_fail (gd != nullptr);
+ auto ymd = GncDate().year_month_day();
+ g_date_set_dmy (gd, ymd.day, static_cast<GDateMonth>(ymd.month), ymd.year);
}
void
commit 2119fceb3a35095a550567db284de86035bb6d59
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Nov 2 22:10:58 2025 +0800
[transaction.cpp] xaccTransSetDate has GDate on stack
avoid malloc/free
diff --git a/libgnucash/engine/Transaction.cpp b/libgnucash/engine/Transaction.cpp
index 32f6f3cb9c..bbc9558dd0 100644
--- a/libgnucash/engine/Transaction.cpp
+++ b/libgnucash/engine/Transaction.cpp
@@ -1968,18 +1968,18 @@ xaccTransSetDateEnteredSecs (Transaction *trans, time64 secs)
void
xaccTransSetDate (Transaction *trans, int day, int mon, int year)
{
- GDate *date;
if (!trans) return;
- date = g_date_new_dmy(day, static_cast<GDateMonth>(mon), year);
- if (!g_date_valid(date))
+ GDate date;
+ g_date_clear (&date, 1);
+ if (g_date_valid_dmy (day, static_cast<GDateMonth>(mon), year))
+ g_date_set_dmy (&date, day, static_cast<GDateMonth>(mon), year);
+ else
{
PWARN("Attempted to set invalid date %d-%d-%d; set today's date instead.",
year, mon, day);
- g_free(date);
- date = gnc_g_date_new_today();
+ gnc_gdate_set_today (&date);
}
- xaccTransSetDatePostedGDate(trans, *date);
- g_free(date);
+ xaccTransSetDatePostedGDate(trans, date);
}
void
Summary of changes:
libgnucash/engine/Transaction.cpp | 14 +++++++-------
libgnucash/engine/gnc-date.cpp | 15 ++++++---------
2 files changed, 13 insertions(+), 16 deletions(-)
More information about the gnucash-changes
mailing list