Re: Simplify formatting.c - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: Simplify formatting.c
Date
Msg-id 200806220243.m5M2hS322144@momjian.us
Whole thread Raw
In response to Re: Simplify formatting.c  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Simplify formatting.c  (Bruce Momjian <bruce@momjian.us>)
List pgsql-patches
Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > Tom Lane wrote:
> >> I'd say not.  Can't we do some more refactoring and avoid so many
> >> useless conversions?  Seems like str_initcap is the wrong primitive API
> >> --- the work ought to be done by a function that takes a char pointer
> >> and a length.  That would be a suitable basis for functions operating
> >> on both text datums and C strings.
>
> > Yea, I thought about that idea too but it is going to add a strlen()
> > calls in some places, but not in critical ones.
>
> Sure, but the cost-per-byte of the strlen should be a good bit less than
> the cost-per-byte of the actual conversion, so that doesn't bother me
> too much.
>
> Actually it seems like the hard part is not so much the input
> representation as the output representation --- what should the
> base-level initcap routine return, to be reasonably efficient for
> both cases?

I hadn't gotten to trying it out yet, but I can see the output being a
problem.  You can't even really pre-allocate the storage before passing
it because you don't know the length after case change.  You could pass
back a char* and repalloc to get the varlena header in there but that is
very messy.

Add to that that the multi-byte case also has to be converted to wide
characters, so you have text -> char * -> wide chars -> char * -> text
for the most complex case.

I am starto to think that the simplest case is to keep the single-copy
version in there for single-byte encodings and not worry about the
overhead of the multi-byte case.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: Simplify formatting.c
Next
From: Thomas Lee
Date:
Subject: A GUC variable to replace PGBE_ACTIVITY_SIZE