Skip site navigation (1) Skip section navigation (2)

Re: Latest on CITEXT 2.0

From: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Latest on CITEXT 2.0
Date: 2008-06-26 16:38:21
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Jun 26, 2008, at 09:19, Alvaro Herrera wrote:

> PG_GETARG_TEXT_P can detoast the datum, which creates a copy.

Thanks. I've just completely refactored things to look more like the  
approach taken by varlena.c, both in terms of when stuff gets freed  
and in terms of coding style. It's more verbose, but I feel much more  
comfortable with memory management now that I'm following a known  
implementation more closely. :-)

So now I've changed citextcmp to this:

static int
citextcmp (text * left, text * right)
     char * lcstr, * rcstr;
     int    result;

     lcstr = cilower( left  );
     rcstr = cilower( right );

     result = varstr_cmp(
         cilower( left ),
         cilower( right ),

     pfree( lcstr );
     pfree( rcstr );
     return result;

And now all of the operator functions are freeing memory using  
PG_FREE_IF_COPY() like this:

	text * left  = PG_GETARG_TEXT_PP(0);
	text * right = PG_GETARG_TEXT_PP(1);
	int32  result;

	result = citextcmp(left, right);

	PG_FREE_IF_COPY(left, 0);
	PG_FREE_IF_COPY(right, 1);

         PG_RETURN_INT32( result );

The only functions that don't do that are citext_smaller() and  

	text * left  = PG_GETARG_TEXT_PP(0);
	text * right = PG_GETARG_TEXT_PP(1);
	text * result;

	result = citextcmp(left, right) < 0 ? left : right;

This is just how varlena.c does it, but I am wondering if something  
*should* be freed there.

Thanks a bunch!



In response to


pgsql-hackers by date

Next:From: Hiroshi SaitoDate: 2008-06-26 16:42:29
Subject: Re: MSVC 2003 compile error with pg8.3.3
Previous:From: Robert HaasDate: 2008-06-26 16:36:15
Subject: Re: Planner creating ineffective plans on LEFT OUTER joins

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group