Re: Why assignment before return? - Mailing list pgsql-hackers

From Thom Brown
Subject Re: Why assignment before return?
Date
Msg-id AANLkTik7vVPmzS7xbAYX9v_kQqN=evXoASS5gMW94BXd@mail.gmail.com
Whole thread Raw
In response to Why assignment before return?  (Magnus Hagander <magnus@hagander.net>)
List pgsql-hackers
On 20 August 2010 12:46, Magnus Hagander <magnus@hagander.net> wrote:
> 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);
> }
>
>
> Why do we assign this to "result" and then return, why not just:
>        if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
>                PG_RETURN_INT64(0);
>        else
>                PG_RETURN_INT64(tabentry->blocks_fetched);
>
>
> --

And then drop the "int64        result;" declaration as a result.

--
Thom Brown
Registered Linux user: #516935


pgsql-hackers by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: git: uh-oh
Next
From: "Kevin Grittner"
Date:
Subject: Re: Avoiding deadlocks ...