[PATCH] Refactor "if(strspn(str, ...) == strlen(str)" code

Поиск
Список
Период
Сортировка
От Aleksander Alekseev
Тема [PATCH] Refactor "if(strspn(str, ...) == strlen(str)" code
Дата
Msg-id 20161208155408.GA27729@e733.localdomain
обсуждение исходный текст
Ответы Re: [PATCH] Refactor "if(strspn(str, ...) == strlen(str)" code  (Geoff Winkless <pgsqladmin@geoff.dj>)
Re: [PATCH] Refactor "if(strspn(str, ...) == strlen(str)" code  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hi.

I noticed that there is a lot of repeating code like this:

```
if (strspn(str, " \t\n\r\f") == strlen(str))
```

I personally don't find it particularly readable, not mentioning that
traversing a string twice doesn't look as a good idea (you can check
using objdump that latest GCC 6.2 doesn't optimize this code).

How about rewriting such a code like this?

```
if (pg_str_containsonly(str, " \t\n\r\f"))
```

Corresponding patch is attached. I don't claim that my implementation of
pg_str_containsonly procedure is faster that strspn + strlen, but at
least such refactoring makes code a little more readable.

--
Best regards,
Aleksander Alekseev

Вложения

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

Предыдущее
От: Christoph Berg
Дата:
Сообщение: Re: Use EVP API pgcrypto encryption, dropping support for OpenSSL 0.9.6 and older
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: Use EVP API pgcrypto encryption, dropping support for OpenSSL 0.9.6 and older