Convert account name, code and description to use string cache.

Plus minor comments and tweaks.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12321 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Chris Shoemaker 2006-01-11 04:30:20 +00:00
parent 0598081427
commit f502a238e4

View File

@ -82,9 +82,9 @@ xaccInitAccount (Account * acc, QofBook *book)
acc->type = NO_TYPE; acc->type = NO_TYPE;
acc->accountName = g_strdup(""); acc->accountName = CACHE_INSERT("");
acc->accountCode = g_strdup(""); acc->accountCode = CACHE_INSERT("");
acc->description = g_strdup(""); acc->description = CACHE_INSERT("");
acc->idata = 0; acc->idata = 0;
@ -139,11 +139,11 @@ xaccCloneAccountSimple(const Account *from, QofBook *book)
* Also let caller issue the generate_event (EVENT_CREATE) */ * Also let caller issue the generate_event (EVENT_CREATE) */
ret->type = from->type; ret->type = from->type;
ret->accountName = g_strdup(from->accountName); ret->accountName = CACHE_INSERT(from->accountName);
ret->accountCode = g_strdup(from->accountCode); ret->accountCode = CACHE_INSERT(from->accountCode);
ret->description = g_strdup(from->description); ret->description = CACHE_INSERT(from->description);
ret->inst.kvp_data = kvp_frame_copy(from->inst.kvp_data); ret->inst.kvp_data = kvp_frame_copy(from->inst.kvp_data);
/* The new book should contain a commodity that matches /* The new book should contain a commodity that matches
* the one in the old book. Find it, use it. */ * the one in the old book. Find it, use it. */
@ -157,6 +157,7 @@ xaccCloneAccountSimple(const Account *from, QofBook *book)
return ret; return ret;
} }
//TODO: Factor from xaccCloneAccount and xaccCloneAccountSimple.
Account * Account *
xaccCloneAccount (const Account *from, QofBook *book) xaccCloneAccount (const Account *from, QofBook *book)
{ {
@ -175,11 +176,11 @@ xaccCloneAccount (const Account *from, QofBook *book)
* Also let caller issue the generate_event (EVENT_CREATE) */ * Also let caller issue the generate_event (EVENT_CREATE) */
ret->type = from->type; ret->type = from->type;
ret->accountName = g_strdup(from->accountName); ret->accountName = CACHE_INSERT(from->accountName);
ret->accountCode = g_strdup(from->accountCode); ret->accountCode = CACHE_INSERT(from->accountCode);
ret->description = g_strdup(from->description); ret->description = CACHE_INSERT(from->description);
ret->inst.kvp_data = kvp_frame_copy(from->inst.kvp_data); ret->inst.kvp_data = kvp_frame_copy(from->inst.kvp_data);
/* The new book should contain a commodity that matches /* The new book should contain a commodity that matches
* the one in the old book. Find it, use it. */ * the one in the old book. Find it, use it. */
@ -263,12 +264,9 @@ xaccFreeAccount (Account *acc)
acc->splits = NULL; acc->splits = NULL;
} }
if (acc->accountName) g_free (acc->accountName); CACHE_REPLACE(acc->accountName, NULL);
acc->accountName = NULL; CACHE_REPLACE(acc->accountCode, NULL);
if (acc->accountCode) g_free (acc->accountCode); CACHE_REPLACE(acc->description, NULL);
acc->accountCode = NULL;
if (acc->description) g_free (acc->description);
acc->description = NULL;
/* zero out values, just in case stray /* zero out values, just in case stray
* pointers are pointing here. */ * pointers are pointing here. */
@ -282,8 +280,6 @@ xaccFreeAccount (Account *acc)
acc->reconciled_balance = gnc_numeric_zero(); acc->reconciled_balance = gnc_numeric_zero();
acc->type = NO_TYPE; acc->type = NO_TYPE;
acc->accountName = NULL;
acc->description = NULL;
acc->commodity = NULL; acc->commodity = NULL;
acc->version = 0; acc->version = 0;
@ -1105,32 +1101,28 @@ xaccAccountSetStartingBalance(Account *acc,
\********************************************************************/ \********************************************************************/
/* CAS: Umm, we say we're checking the split, but we're actually /* CAS: Umm, we say we're checking the split, but we're actually
resorting all the splits. Why not just leave the split out of resorting all the splits. Why not just leave the split out of
it? */ it? FIXME. */
void void
xaccAccountFixSplitDateOrder (Account * acc, Split *split) xaccAccountFixSplitDateOrder (Account * acc, Split *split)
{ {
if (NULL == acc) return; if (!acc || !split || acc->inst.do_free) return;
if (NULL == split) return;
if (acc->inst.do_free) return;
/* FIXME: This looks wrong, too. Why force it dirty if it's not? */
acc->sort_dirty = TRUE; acc->sort_dirty = TRUE;
acc->balance_dirty = TRUE; acc->balance_dirty = TRUE;
if (acc->inst.editlevel > 0) return; if (acc->inst.editlevel <= 0)
xaccAccountBringUpToDate (acc);
xaccAccountBringUpToDate (acc);
} }
/********************************************************************\ /********************************************************************\
* xaccCheckTransDateOrder * * xaccTransFixSplitDateOrder *
* check this transaction to see if the date is in correct order * * check this transaction to see if the date is in correct order *
* If it is not, reorder the transactions. * * If it is not, reorder the transactions. *
* This routine perfroms the check for both of the double-entry * * This routine perfroms the check for both of the double-entry *
* transaction entries. * * transaction entries. *
* * * *
* Args: trans -- the transaction to check * * Args: trans -- the transaction to check *
* Return: int -- non-zero if out of order *
\********************************************************************/ \********************************************************************/
void void
@ -1138,7 +1130,7 @@ xaccTransFixSplitDateOrder (Transaction *trans)
{ {
GList *node; GList *node;
if (trans == NULL) return; if (!trans) return;
gnc_engine_suspend_events(); gnc_engine_suspend_events();
for (node = trans->splits; node; node = node->next) for (node = trans->splits; node; node = node->next)
@ -1237,15 +1229,10 @@ xaccAccountSetType (Account *acc, GNCAccountType tip)
void void
xaccAccountSetName (Account *acc, const char *str) xaccAccountSetName (Account *acc, const char *str)
{ {
char * tmp;
if (!acc || !str || str == acc->accountName) return; if (!acc || !str || str == acc->accountName) return;
xaccAccountBeginEdit(acc); xaccAccountBeginEdit(acc);
/* make strdup before freeing (just in case str==accountName !!) */ CACHE_REPLACE(acc->accountName, str);
tmp = g_strdup (str);
g_free (acc->accountName);
acc->accountName = tmp; /* TODO: use string cache */
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit(acc); xaccAccountCommitEdit(acc);
@ -1254,14 +1241,10 @@ xaccAccountSetName (Account *acc, const char *str)
void void
xaccAccountSetCode (Account *acc, const char *str) xaccAccountSetCode (Account *acc, const char *str)
{ {
char * tmp;
if (!acc || !str || str == acc->accountCode) return; if (!acc || !str || str == acc->accountCode) return;
xaccAccountBeginEdit(acc); xaccAccountBeginEdit(acc);
/* make strdup before freeing */ CACHE_REPLACE(acc->accountCode, str);
tmp = g_strdup (str);
g_free (acc->accountCode);
acc->accountCode = tmp; /* TODO: use string cache */
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit(acc); xaccAccountCommitEdit(acc);
@ -1270,14 +1253,10 @@ xaccAccountSetCode (Account *acc, const char *str)
void void
xaccAccountSetDescription (Account *acc, const char *str) xaccAccountSetDescription (Account *acc, const char *str)
{ {
char * tmp;
if (!acc || !str || str == acc->description) return; if (!acc || !str || str == acc->description) return;
xaccAccountBeginEdit(acc); xaccAccountBeginEdit(acc);
/* make strdup before freeing (just in case str==description !!) */ CACHE_REPLACE(acc->description, str);
tmp = g_strdup (str);
g_free (acc->description);
acc->description = tmp; /* TODO: use string cache */
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit(acc); xaccAccountCommitEdit(acc);