Re: Why assignment before return?

Поиск
Список
Период
Сортировка
От Magnus Hagander
Тема Re: Why assignment before return?
Дата
Msg-id AANLkTimQGdkLmW+qyKNDL85xNAd8hNzmJGWivj_phGPZ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Why assignment before return?  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Why assignment before return?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Fri, Aug 20, 2010 at 15:10, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Magnus Hagander <magnus@hagander.net> writes:
>> This code-pattern appears many times in pgstatfuncs.c:
>> Datum
>> pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS)
>> {
>>       Oid                     relid = PG_GETARG_OID(0);
>>       int64           result;
>>       PgStat_StatTabEntry *tabentry;
>
>>       if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
>>               result = 0;
>>       else
>>               result = (int64) (tabentry->blocks_fetched);
>
>>       PG_RETURN_INT64(result);
>> }
>
>
> I see nothing wrong with that style.  Reducing it as you propose
> probably wouldn't change the emitted code at all, and what it would
> do is reduce flexibility.  For instance, if we ever needed to add
> additional operations just before the RETURN (releasing a lock on
> the tabentry, perhaps) we'd just have to undo the "improvement".

I'm not saying it's wrong, I'm just trying to figure out why it's
there since I wanted to add other functions and it looked.. Odd. I'll
change my new functions to look like this for consistency, but I was
curious if there was some specific reason why it was better to do it
this way.

I see your answer as "no, not really any reason, but also not worth
changing", which is fine by me :-)


--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Heikki Linnakangas
Дата:
Сообщение: Re: CommitFest 2009-07: Yay, Kevin! Thanks, reviewers!
Следующее
От: Tom Lane
Дата:
Сообщение: Re: CommitFest 2009-07: Yay, Kevin! Thanks, reviewers!