From 0e37e059d504d9e2ab2ececd0979ec87a93fea1e Mon Sep 17 00:00:00 2001 From: "Christopher D. Carson" Date: Sat, 29 Dec 2018 06:45:47 -0600 Subject: [PATCH] Fix XML load CPU hotspot: Scrub.c xaccTransScrubPostedDate The refactoring provides roughly 10% reduction in user CPU use for XML file load by moving an expensive function to within an if-clause where the result is used. The diff looks like a full re-write but only the if statements, indenting, and commentary changed. --- libgnucash/engine/Scrub.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libgnucash/engine/Scrub.c b/libgnucash/engine/Scrub.c index d6ff1075ff..4b3215065d 100644 --- a/libgnucash/engine/Scrub.c +++ b/libgnucash/engine/Scrub.c @@ -1395,13 +1395,15 @@ void xaccTransScrubPostedDate (Transaction *trans) { time64 orig = xaccTransGetDate(trans); - GDate date = xaccTransGetDatePostedGDate(trans); - time64 time = gdate_to_time64(date); - /* xaccTransGetDatePostedGDate will return a valid time */ - if (orig == INT64_MAX && orig != time) + if(orig == INT64_MAX) { - /* xaccTransSetDatePostedSecs handles committing the change. */ - xaccTransSetDatePostedSecs(trans, time); + GDate date = xaccTransGetDatePostedGDate(trans); + time64 time = gdate_to_time64(date); + if(time != INT64_MAX) + { + // xaccTransSetDatePostedSecs handles committing the change. + xaccTransSetDatePostedSecs(trans, time); + } } }