r15790 - gnucash/trunk/src/engine - Patch from Klee Dienes <klee at mit.edu> (bugzilla #420550) to

David Hampton hampton at cvs.gnucash.org
Wed Apr 4 00:36:17 EDT 2007


Author: hampton
Date: 2007-04-04 00:36:16 -0400 (Wed, 04 Apr 2007)
New Revision: 15790
Trac: http://svn.gnucash.org/trac/changeset/15790

Modified:
   gnucash/trunk/src/engine/gnc-lot.c
Log:
Patch from Klee Dienes <klee at mit.edu> (bugzilla #420550) to
re-implement gnc_lot_get_earliest_split and gnc_lot_get_latest_split
using xaccSplitDateOrder.  This greatly simplifies the functions.


Modified: gnucash/trunk/src/engine/gnc-lot.c
===================================================================
--- gnucash/trunk/src/engine/gnc-lot.c	2007-04-04 04:16:57 UTC (rev 15789)
+++ gnucash/trunk/src/engine/gnc-lot.c	2007-04-04 04:36:16 UTC (rev 15790)
@@ -370,59 +370,25 @@
 Split *
 gnc_lot_get_earliest_split (GNCLot *lot)
 {
-   SplitList *node;
-   Timespec ts;
-   Split *earliest = NULL;
-
-   ts.tv_sec = ((long long) ULONG_MAX);
-   ts.tv_nsec = 0;
-   if (!lot) return NULL;
-
-   for (node=lot->splits; node; node=node->next)
-   {
-      Split *s = node->data;
-      Transaction *trans = s->parent;
-      if (!trans) continue;
-      if ((ts.tv_sec > trans->date_posted.tv_sec) ||
-          ((ts.tv_sec == trans->date_posted.tv_sec) &&
-           (ts.tv_nsec > trans->date_posted.tv_nsec)))
-          
-      {
-         ts = trans->date_posted;
-         earliest = s;
-      }
-   }
-
-   return earliest;
+  if (! lot->splits)
+    return NULL;
+  lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitDateOrder);
+  return lot->splits->data;
 }
 
 Split *
 gnc_lot_get_latest_split (GNCLot *lot)
 {
-   SplitList *node;
-   Timespec ts;
-   Split *latest = NULL;
+  SplitList *node;
 
-   ts.tv_sec = 0;
-   ts.tv_nsec = 0;
-   if (!lot) return NULL;
+  if (! lot->splits)
+    return NULL;
+  lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitDateOrder);
 
-   for (node=lot->splits; node; node=node->next)
-   {
-      Split *s = node->data;
-      Transaction *trans = s->parent;
-      if (!trans) continue;
-      if ((ts.tv_sec < trans->date_posted.tv_sec) ||
-          ((ts.tv_sec == trans->date_posted.tv_sec) &&
-           (ts.tv_nsec < trans->date_posted.tv_nsec)))
-          
-      {
-         ts = trans->date_posted;
-         latest = s;
-      }
-   }
+  for (node = lot->splits; node->next; node = node->next)
+    ;
 
-   return latest;
+  return node->data;
 }
 
 /* ============================================================= */



More information about the gnucash-changes mailing list