Re: Optimize LISTEN/NOTIFY

Поиск
Список
Период
Сортировка
От Chao Li
Тема Re: Optimize LISTEN/NOTIFY
Дата
Msg-id 6055D998-7333-4094-9BEA-F52EFC5338A9@gmail.com
обсуждение исходный текст
Ответ на Re: Optimize LISTEN/NOTIFY  (Chao Li <li.evan.chao@gmail.com>)
Список pgsql-hackers


On Oct 8, 2025, at 11:43, Chao Li <li.evan.chao@gmail.com> wrote:

6
```
+static inline void
+ChannelHashPrepareKey(ChannelHashKey *key, Oid dboid, const char *channel)
+{
+ memset(key, 0, sizeof(ChannelHashKey));
+ key->dboid = dboid;
+ strlcpy(key->channel, channel, NAMEDATALEN);
+}
```

Do we really need the memset()? If “channel” is of length NAMEDATALEN, then it still results in a non-0 terminated key->channel; if channel is shorter than NAMEDATALEN, strlcpy will auto add a tailing ‘\0’. I think previous code should have ensured length of channel should be less than NAMEDATALEN.

For comment 6, the result is the same that I don’t think memset() is needed. However, my previous explanation of strlcpy() was wrong, which should apply to strncpy(). For strlcpy(), it already makes a termination ‘\0’.

And one more nit comment:

9
```
+ int allocated_listeners; /* Allocated size of array */
```

For “size” here, I guess you meant “length”, though “size” also works, but usually “size” means bytes occupied by an array and “length” means number of elements of an array. So, “length” would be clearer here.

--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/




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