remove pointless maloc/free, should improve file load performance a

teeny bit.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9200 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas
2003-09-01 15:08:26 +00:00
parent b3866e396b
commit 709adddc81
14 changed files with 73 additions and 83 deletions

View File

@@ -191,7 +191,7 @@ struct account_pdata
QofBook *book;
};
static gboolean
static inline gboolean
set_string(xmlNodePtr node, Account* act,
void (*func)(Account *act, const gchar *txt))
{

View File

@@ -106,10 +106,9 @@ price_parse_xml_sub_node(GNCPrice *p, xmlNodePtr sub_node, QofBook *book)
if(!c) return FALSE;
gnc_price_set_currency(p, c);
} else if(safe_strcmp("price:time", sub_node->name) == 0) {
Timespec *t = dom_tree_to_timespec(sub_node);
if(!t) return FALSE;
gnc_price_set_time(p, *t);
g_free(t);
Timespec t = dom_tree_to_timespec(sub_node);
if(!is_valid_timespec(t)) return FALSE;
gnc_price_set_time(p, t);
} else if(safe_strcmp("price:source", sub_node->name) == 0) {
char *text = dom_tree_to_text(sub_node);
if(!text) return FALSE;

View File

@@ -202,7 +202,7 @@ struct split_pdata
QofBook *book;
};
static gboolean
static inline gboolean
set_spl_string(xmlNodePtr node, Split *spl,
void (*func)(Split *spl, const char *txt))
{
@@ -216,7 +216,7 @@ set_spl_string(xmlNodePtr node, Split *spl,
return TRUE;
}
static gboolean
static inline gboolean
set_spl_gnc_num(xmlNodePtr node, Split* spl,
void (*func)(Split *spl, gnc_numeric gn))
{
@@ -275,14 +275,12 @@ static gboolean
spl_reconcile_date_handler(xmlNodePtr node, gpointer data)
{
struct split_pdata *pdata = data;
Timespec *ts;
Timespec ts;
ts = dom_tree_to_timespec(node);
g_return_val_if_fail(ts, FALSE);
g_return_val_if_fail(is_valid_timespec(ts), FALSE);
xaccSplitSetDateReconciledTS(pdata->split, ts);
g_free(ts);
xaccSplitSetDateReconciledTS(pdata->split, &ts);
return TRUE;
}
@@ -415,7 +413,7 @@ struct trans_pdata
QofBook *book;
};
static gboolean
static inline gboolean
set_tran_string(xmlNodePtr node, Transaction *trn,
void (*func)(Transaction *trn, const char *txt))
{
@@ -432,24 +430,22 @@ set_tran_string(xmlNodePtr node, Transaction *trn,
return TRUE;
}
static gboolean
static inline gboolean
set_tran_date(xmlNodePtr node, Transaction *trn,
void (*func)(Transaction *trn, const Timespec *tm))
{
Timespec *tm;
Timespec tm;
tm = dom_tree_to_timespec(node);
g_return_val_if_fail(tm, FALSE);
g_return_val_if_fail(is_valid_timespec(tm), FALSE);
func(trn, tm);
g_free(tm);
func(trn, &tm);
return TRUE;
}
static gboolean
static inline gboolean
trn_id_handler(xmlNodePtr node, gpointer trans_pdata)
{
struct trans_pdata *pdata = trans_pdata;

View File

@@ -3585,10 +3585,9 @@ price_parse_xml_sub_node(GNCPrice *p, xmlNodePtr sub_node, QofBook *book)
if(!c) return FALSE;
gnc_price_set_currency(p, c);
} else if(safe_strcmp("price:time", sub_node->name) == 0) {
Timespec *t = dom_tree_to_timespec(sub_node);
if(!t) return FALSE;
gnc_price_set_time(p, *t);
g_free(t);
Timespec t = dom_tree_to_timespec(sub_node);
if(!is_valid_timespec(t)) return FALSE;
gnc_price_set_time(p, t);
} else if(safe_strcmp("price:source", sub_node->name) == 0) {
char *text = dom_tree_to_text(sub_node);
if(!text) return FALSE;

View File

@@ -189,15 +189,14 @@ dom_tree_to_guid_kvp_value(xmlNodePtr node)
kvp_value*
dom_tree_to_timespec_kvp_value (xmlNodePtr node)
{
Timespec * ts;
Timespec ts;
kvp_value * ret = NULL;
ts = dom_tree_to_timespec (node);
if (ts)
ret = kvp_value_new_timespec (*ts);
g_free (ts);
if (ts.tv_sec || ts.tv_nsec)
{
ret = kvp_value_new_timespec (ts);
}
return ret;
}
@@ -493,18 +492,16 @@ dom_tree_to_gnc_numeric(xmlNodePtr node)
}
}
static Timespec*
timespec_failure(Timespec *would_have_been)
static inline Timespec
timespec_failure(Timespec ts)
{
if(would_have_been)
{
g_free(would_have_been);
}
return NULL;
ts.tv_sec = 0;
ts.tv_nsec = 0;
return ts;
}
Timespec*
Timespec
dom_tree_to_timespec(xmlNodePtr node)
{
/* Turn something like this
@@ -518,15 +515,14 @@ dom_tree_to_timespec(xmlNodePtr node)
undefined. The XML is valid if it has at least one of <s> or <ns>
and no more than one of each. Order is irrelevant. */
Timespec *ret;
Timespec ret;
gboolean seen_s = FALSE;
gboolean seen_ns = FALSE;
xmlNodePtr n;
ret = g_new(Timespec, 1);
ret->tv_sec = 0;
ret->tv_nsec = 0;
ret.tv_sec = 0;
ret.tv_nsec = 0;
for(n = node->xmlChildrenNode; n; n = n->next) {
switch(n->type) {
case XML_COMMENT_NODE:
@@ -546,7 +542,7 @@ dom_tree_to_timespec(xmlNodePtr node)
return timespec_failure(ret);
}
if(!string_to_timespec_secs(content, ret)) {
if(!string_to_timespec_secs(content, &ret)) {
g_free(content);
return timespec_failure(ret);
}
@@ -567,7 +563,7 @@ dom_tree_to_timespec(xmlNodePtr node)
return timespec_failure(ret);
}
if(!string_to_timespec_nsecs(content, ret)) {
if(!string_to_timespec_nsecs(content, &ret)) {
g_free(content);
return timespec_failure(ret);
}
@@ -732,7 +728,7 @@ dom_tree_to_commodity_ref(xmlNodePtr node, QofBook *book)
daref = dom_tree_to_commodity_ref_no_engine(node, book);
table = gnc_book_get_commodity_table (book);
table = gnc_commodity_table_get_table (book);
g_return_val_if_fail (table != NULL, NULL);
@@ -750,7 +746,7 @@ dom_tree_to_commodity_ref(xmlNodePtr node, QofBook *book)
/***********************************************************************/
/* generic parser */
static void
static inline void
dom_tree_handlers_reset(struct dom_tree_handler *handlers)
{
for(;handlers->tag != NULL; handlers++)
@@ -759,7 +755,7 @@ dom_tree_handlers_reset(struct dom_tree_handler *handlers)
}
}
static gboolean
static inline gboolean
dom_tree_handlers_all_gotten_p(struct dom_tree_handler *handlers)
{
gboolean ret = TRUE;
@@ -776,7 +772,7 @@ dom_tree_handlers_all_gotten_p(struct dom_tree_handler *handlers)
}
static gboolean
static inline gboolean
gnc_xml_set_data(const gchar* tag, xmlNodePtr node, gpointer item,
struct dom_tree_handler *handlers)
{

View File

@@ -45,7 +45,8 @@ gnc_commodity *dom_tree_to_commodity_ref_no_engine(xmlNodePtr node, QofBook *);
FreqSpec* dom_tree_to_freqSpec( xmlNodePtr node, QofBook *book);
Timespec* dom_tree_to_timespec(xmlNodePtr node);
Timespec dom_tree_to_timespec(xmlNodePtr node);
#define is_valid_timespec(ts) (ts.tv_sec || ts.tv_nsec)
GDate* dom_tree_to_gdate(xmlNodePtr node);
gnc_numeric* dom_tree_to_gnc_numeric(xmlNodePtr node);
gchar * dom_tree_to_text(xmlNodePtr tree);

View File

@@ -82,7 +82,7 @@ test_dom_tree_to_text(void)
}
else
{
failure_args("dom_tree_to_text", __FILE__, __LINE__,
failure_args("dom_tree_to_text", __FILE__, __LINE__,
"with string %s", test_string1);
}
@@ -100,7 +100,7 @@ test_dom_tree_to_timespec(void)
for(i = 0; i < 20; i++)
{
Timespec *test_spec1;
Timespec *test_spec2;
Timespec test_spec2;
xmlNodePtr test_node;
test_spec1 = get_random_timespec();
@@ -109,7 +109,7 @@ test_dom_tree_to_timespec(void)
test_spec2 = dom_tree_to_timespec(test_node);
if(test_spec2 == NULL)
if(!is_valid_timespec(test_spec2))
{
failure_args("dom_tree_to_timespec",
__FILE__, __LINE__, "NULL return");
@@ -118,7 +118,7 @@ test_dom_tree_to_timespec(void)
printf("\n");
}
else if(timespec_cmp(test_spec1, test_spec2) == 0)
else if(timespec_cmp(test_spec1, &test_spec2) == 0)
{
success("dom_tree_to_timespec");
}
@@ -130,14 +130,13 @@ test_dom_tree_to_timespec(void)
printf("\n");
printf("Secs are %lld vs %lld :: ",
test_spec1->tv_sec,
test_spec2->tv_sec);
test_spec2.tv_sec);
printf("NSecs are %ld vs %ld\n",
test_spec1->tv_nsec,
test_spec2->tv_nsec);
test_spec2.tv_nsec);
}
g_free(test_spec1);
g_free(test_spec2);
xmlFreeNode(test_node);
}
}
@@ -223,7 +222,7 @@ test_dom_tree_to_guid(void)
if (!(test_node = guid_to_dom_tree("test-guid", test_guid1)))
{
failure_args("guid_to_dom_tree", __FILE__, __LINE__,
failure_args("guid_to_dom_tree", __FILE__, __LINE__,
"conversion to dom tree failed");
}

View File

@@ -242,15 +242,15 @@ equals_node_val_vs_kvp_frame(xmlNodePtr node, const kvp_frame *frm)
gboolean
equals_node_val_vs_date(xmlNodePtr node, const Timespec tm)
{
Timespec *tm_test = dom_tree_to_timespec(node);
Timespec tm_test = dom_tree_to_timespec(node);
if(tm_test->tv_sec == tm.tv_sec && tm_test->tv_nsec == tm.tv_nsec)
if(tm_test.tv_sec == tm.tv_sec && tm_test.tv_nsec == tm.tv_nsec)
{
return TRUE;
}
else
{
return TRUE;
return FALSE;
}
}

View File

@@ -51,7 +51,7 @@ guile_main (void *closure, int argc, char **argv)
if (!location)
{
location = "../../../../accounts/C";
location = "../../../../accounts/C";
}
gnc_module_system_init();

View File

@@ -87,7 +87,7 @@ guile_main (void *closure, int argc, char **argv)
if (!location)
{
location = "test-files/xml2";
location = "test-files/xml2";
}
gnc_module_system_init();

View File

@@ -215,7 +215,7 @@ test_add_account(const char *tag, gpointer globaldata, gpointer data)
do_test_args(xaccAccountEqual((Account*)data, (Account*)(gdata->act),
TRUE),
"gnc_account_sixtp_parser_create",
__FILE__, __LINE__, "%d", gdata->value );
__FILE__, __LINE__, "%d", gdata->value );
return TRUE;
}

View File

@@ -130,8 +130,8 @@ test_add_commodity(const char *tag, gpointer globaldata, gpointer data)
com_data *gdata = (com_data*)globaldata;
do_test_args(gnc_commodity_equiv((gnc_commodity*)data, gdata->com),
"gnc_commodity_sixtp_parser_create",
__FILE__, __LINE__, "%d", gdata->value );
"gnc_commodity_sixtp_parser_create",
__FILE__, __LINE__, "%d", gdata->value );
gnc_commodity_destroy((gnc_commodity*)data);
return TRUE;
@@ -155,7 +155,7 @@ test_generation(void)
test_node = gnc_commodity_dom_tree_create(ran_com);
if(!test_node)
{
failure_args("commodity_xml", __FILE__, __LINE__,
failure_args("commodity_xml", __FILE__, __LINE__,
"gnc_commodity_dom_tree_create returned NULL");
gnc_commodity_destroy(ran_com);
continue;
@@ -197,7 +197,7 @@ test_generation(void)
(gpointer)&data, book))
{
failure_args("gnc_xml_parse_file returned FALSE",
__FILE__, __LINE__, "%d", i);
__FILE__, __LINE__, "%d", i);
}
/* no handling of circular data structures. We'll do that later */

View File

@@ -123,21 +123,21 @@ equals_node_val_vs_split_internal(xmlNodePtr node, Split* spl)
else if(safe_strcmp(mark->name, "split:value") == 0)
{
gnc_numeric *num = dom_tree_to_gnc_numeric(mark);
gnc_numeric val = xaccSplitGetValue(spl);
gnc_numeric val = xaccSplitGetValue(spl);
if(!gnc_numeric_equal(*num, val))
{
g_free(num);
return g_strdup_printf ("values differ: %lld/%lld v %lld/%lld",
(*num).num, (*num).denom,
val.num, val.denom);
(*num).num, (*num).denom,
val.num, val.denom);
}
g_free(num);
}
else if(safe_strcmp(mark->name, "split:quantity") == 0)
{
gnc_numeric *num = dom_tree_to_gnc_numeric(mark);
gnc_numeric val = xaccSplitGetAmount(spl);
gnc_numeric val = xaccSplitGetAmount(spl);
if (!gnc_numeric_equal(*num, val)) {
return g_strdup_printf( "quantities differ under _equal: %lld/%lld v %lld/%lld",
@@ -148,8 +148,8 @@ equals_node_val_vs_split_internal(xmlNodePtr node, Split* spl)
{
g_free(num);
return g_strdup_printf ("quantities differ: %lld/%lld v %lld/%lld",
(*num).num, (*num).denom,
val.num, val.denom);
(*num).num, (*num).denom,
val.num, val.denom);
}
g_free(num);
}
@@ -191,7 +191,7 @@ equals_node_val_vs_splits(xmlNodePtr node, const Transaction *trn)
return "no matching split found";
}
msg = equals_node_val_vs_split_internal(spl_node, spl_mark);
msg = equals_node_val_vs_split_internal(spl_node, spl_mark);
if(msg != NULL)
{
return msg;
@@ -276,10 +276,10 @@ node_and_transaction_equal(xmlNodePtr node, Transaction *trn)
}
else if(safe_strcmp(mark->name, "trn:splits") == 0)
{
char *msg = equals_node_val_vs_splits (mark, trn);
char *msg = equals_node_val_vs_splits (mark, trn);
if(msg != NULL)
{
return msg;
return msg;
}
}
else
@@ -319,9 +319,9 @@ test_add_transaction(const char *tag, gpointer globaldata, gpointer data)
xaccTransCommitEdit (trans);
if (!do_test_args(xaccTransEqual(gdata->trn, trans, TRUE, TRUE, TRUE, FALSE),
"gnc_transaction_sixtp_parser_create",
__FILE__, __LINE__,
"%d", gdata->value))
"gnc_transaction_sixtp_parser_create",
__FILE__, __LINE__,
"%d", gdata->value))
return FALSE;
gdata->new_trn = trans;
@@ -346,7 +346,7 @@ test_transaction(void)
ran_trn = get_random_transaction(book);
{
/* xaccAccountInsertSplit can reorder the splits. */
/* xaccAccountInsertSplit can reorder the splits. */
GList * list = g_list_copy(xaccTransGetSplitList (ran_trn));
GList * node = list;
for ( ; node; node = node->next)
@@ -359,7 +359,7 @@ test_transaction(void)
xaccAccountInsertSplit (a, s);
xaccAccountCommitEdit (a);
}
g_list_free(list);
g_list_free(list);
}
com = xaccTransGetCurrency (ran_trn);
@@ -428,7 +428,7 @@ test_transaction(void)
(gpointer)&data, book))
{
failure_args("gnc_xml_parse_file returned FALSE",
__FILE__, __LINE__, "%d", i);
__FILE__, __LINE__, "%d", i);
}
else
really_get_rid_of_transaction (data.new_trn);

View File

@@ -17,7 +17,7 @@ main(int argc, char **argv)
if (!directory)
{
directory = "../../../../accounts/C";
directory = "../../../../accounts/C";
}
filename = malloc(strlen(directory) + 1 + strlen(FILENAME) + 1);