Skip to content

Commit 7bdf31f

Browse files
[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
1 parent 2119fce commit 7bdf31f

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

libgnucash/engine/gnc-date.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,20 +1230,17 @@ GDate time64_to_gdate (time64 t)
12301230

12311231
GDate* gnc_g_date_new_today ()
12321232
{
1233-
GncDate gncd;
1234-
auto ymd = gncd.year_month_day();
1235-
auto month = static_cast<GDateMonth>(ymd.month);
1236-
auto result = g_date_new_dmy (ymd.day, month, ymd.year);
1237-
g_assert(g_date_valid (result));
1238-
return result;
1233+
GDate* rv = g_date_new ();
1234+
gnc_gdate_set_today (rv);
1235+
return rv;
12391236
}
12401237

12411238
void
12421239
gnc_gdate_set_today (GDate* gd)
12431240
{
1244-
GDate *today = gnc_g_date_new_today ();
1245-
g_date_set_julian (gd, g_date_get_julian (today));
1246-
g_date_free (today);
1241+
g_return_if_fail (gd != nullptr);
1242+
auto ymd = GncDate().year_month_day();
1243+
g_date_set_dmy (gd, ymd.day, static_cast<GDateMonth>(ymd.month), ymd.year);
12471244
}
12481245

12491246
void

0 commit comments

Comments
 (0)