Re: trivial refactoring of WaitOnLock - Mailing list pgsql-patches

From Neil Conway
Subject Re: trivial refactoring of WaitOnLock
Date
Msg-id 422EE68E.2030105@samurai.com
Whole thread Raw
In response to Re: trivial refactoring of WaitOnLock  (Russell Smith <mr-russ@pws.com.au>)
Responses Re: trivial refactoring of WaitOnLock
List pgsql-patches
Russell Smith wrote:
> *** 1083,1091 ****
>                            locallock->lock, locallock->tag.mode);
>
>         old_status = pstrdup(get_ps_display());
> !       new_status = (char *) palloc(strlen(old_status) + 10);
>         strcpy(new_status, old_status);
> !       strcat(new_status, " waiting");
>         set_ps_display(new_status);
>
>         awaitedLock = locallock;
> --- 1084,1093 ----
>                            locallock->lock, locallock->tag.mode);
>
>         old_status = pstrdup(get_ps_display());
> !       len = strlen(old_status);
> !       new_status = (char *) palloc(len + 9);
>         strcpy(new_status, old_status);
> !       strcpy(&new_status[len], " waiting");
>         set_ps_display(new_status);

memcpy(new_status, old_status, len) would be faster yet. Which is what I
originally implemented, and then decided the sprintf() was clearer
(since performance isn't very important here). On reflection, memcpy() +
strcpy() should be fine; I'll commit this tomorrow.

-Neil

pgsql-patches by date:

Previous
From: "Qingqing Zhou"
Date:
Subject: Re: trivial refactoring of WaitOnLock
Next
From: "Luiz K. Matsumura"
Date:
Subject: problem with CR+LF in files in psql \i command