Re: Latest on CITEXT 2.0 - Mailing list pgsql-hackers

From David E. Wheeler
Subject Re: Latest on CITEXT 2.0
Date
Msg-id 7BDE8C80-B9FC-459A-902C-2EDF99A5C8EF@kineticode.com
Whole thread Raw
In response to Re: Latest on CITEXT 2.0  (Alvaro Herrera <alvherre@commandprompt.com>)
Responses Re: Latest on CITEXT 2.0  (Josh Berkus <josh@agliodbs.com>)
List 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 ),        VARSIZE_ANY_EXHDR(left),        cilower( right ),
VARSIZE_ANY_EXHDR(right)   );
 
    pfree( lcstr );    pfree( rcstr );    return result;
}

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

Datum
citext_cmp(PG_FUNCTION_ARGS)
{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  
citext_larger():

Datum
citext_smaller(PG_FUNCTION_ARGS)
{text * left  = PG_GETARG_TEXT_PP(0);text * right = PG_GETARG_TEXT_PP(1);text * result;
result = citextcmp(left, right) < 0 ? left : right;PG_RETURN_TEXT_P(result);
}

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

Thanks a bunch!

Best,

David



pgsql-hackers by date:

Previous
From: "Robert Haas"
Date:
Subject: Re: Planner creating ineffective plans on LEFT OUTER joins
Next
From: "Hiroshi Saito"
Date:
Subject: Re: MSVC 2003 compile error with pg8.3.3