From 90d76525c5cc2f3f4781351a1d99be839dfa2874 Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Sat, 3 Mar 2007 19:32:55 +0000 Subject: Add resetStringInfo(), which clears the content of a StringInfo, and fixup various places in the tree that were clearing a StringInfo by hand. Making this function a part of the API simplifies client code slightly, and avoids needlessly peeking inside the StringInfo interface. --- contrib/tablefunc/tablefunc.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'contrib/tablefunc/tablefunc.c') diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c index 4e68428e0d..f3b1eb2a8b 100644 --- a/contrib/tablefunc/tablefunc.c +++ b/contrib/tablefunc/tablefunc.c @@ -1378,15 +1378,12 @@ build_tuplestore_recursively(char *key_fld, "incompatible."))); } + initStringInfo(&branchstr); + initStringInfo(&chk_branchstr); + initStringInfo(&chk_current_key); + for (i = 0; i < proc; i++) { - /* start a new branch */ - initStringInfo(&branchstr); - - /* need these to check for recursion */ - initStringInfo(&chk_branchstr); - initStringInfo(&chk_current_key); - /* initialize branch for this pass */ appendStringInfo(&branchstr, "%s", branch); appendStringInfo(&chk_branchstr, "%s%s%s", branch_delim, branch, branch_delim); @@ -1459,10 +1456,14 @@ build_tuplestore_recursively(char *key_fld, tupstore); /* reset branch for next pass */ - xpfree(branchstr.data); - xpfree(chk_branchstr.data); - xpfree(chk_current_key.data); + resetStringInfo(&branchstr); + resetStringInfo(&chk_branchstr); + resetStringInfo(&chk_current_key); } + + xpfree(branchstr.data); + xpfree(chk_branchstr.data); + xpfree(chk_current_key.data); } return tupstore; -- cgit v1.2.3