From: Michael Paquier Date: Fri, 8 Sep 2023 01:00:29 +0000 (+0900) Subject: Improve BackendXidGetPid() to only access allProcs on matching XID X-Git-Tag: REL_17_BETA1~1897 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e722846daf4a37797ee39bc8ca3e78a4ef437f51;p=thirdparty%2Fpostgresql.git Improve BackendXidGetPid() to only access allProcs on matching XID Compilers are able to optimize that, but it makes the code slightly more readable this way. Author: Zhao Junwang Reviewed-by: Ashutosh Bapat Discussion: https://postgr.es/m/CAEG8a3+i9gtqF65B+g_puVaCQuf0rZC-EMqMyEjGFJYOqUUWfA@mail.gmail.com --- diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index bfbf7f903f5..d93475b2bdd 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -3174,11 +3174,11 @@ BackendXidGetPid(TransactionId xid) for (index = 0; index < arrayP->numProcs; index++) { - int pgprocno = arrayP->pgprocnos[index]; - PGPROC *proc = &allProcs[pgprocno]; - if (other_xids[index] == xid) { + int pgprocno = arrayP->pgprocnos[index]; + PGPROC *proc = &allProcs[pgprocno]; + result = proc->pid; break; }