cleanup StringInfo usage

Поиск
Список
Период
Сортировка
От Neil Conway
Тема cleanup StringInfo usage
Дата
Msg-id 1141154470.8830.266.camel@localhost.localdomain
обсуждение исходный текст
Ответы Re: cleanup StringInfo usage  (Neil Conway <neilc@samurai.com>)
Список pgsql-patches
Attached is a patch that replaces a bunch of places where StringInfos
are unnecessarily allocated on the heap rather than the stack. That is,
this is sub-optimal:

{
    StringInfo str;

    str = makeStringInfo();
    /* use str */

    pfree(str->data);
    pfree(str);
}

If the StringInfo doesn't outlive the stack frame in which it is
created, there is no need to allocate it on the heap via
makeStringInfo() -- stack allocation is faster:

{
    StringInfoData str;

    initStringInfo(&str);
    /* use str */

    pfree(str.data);
}

While it's not a big deal unless the code is in a critical path, I don't
see a reason not to save a few cycles -- using stack allocation is not
less readable.

A bunch of places in the tree (mostly contrib/) were using
makeStringInfo() when there was no need to do so -- this patch replaces
that with a stack-allocated StringInfoData and initStringInfo(). I also
cleaned up a bit of code along the way: moved variable declarations into
a more tightly-enclosing scope where possible, fixed some pointless
copying of strings in dblink, etc.

Barring any objections I'll apply this tomorrow.

-Neil


Вложения

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] how solve diff of API counstruct_md_array between
Следующее
От: Neil Conway
Дата:
Сообщение: Re: <> operator