[Dovecot] Why p_strdup and other string functions uses loops instead strlen? (dovecot 2.0.rc4)
Timo Sirainen
tss at iki.fi
Tue Aug 10 15:08:14 EEST 2010
On 10.8.2010, at 10.30, Len7hir wrote:
> I did Dovecot profiling on huge e-mail system, and p_strdup was very high on list.
>
> I do minor change:
> p_strdup:
> /*
> for (len = 0; (str)[len] != '\0'; )
> len++;
> len++;
> */
> len = strlen(str) + 1;
Committed: http://hg.dovecot.org/dovecot-2.0/rev/7f550a7bd9d7
> p_strndup:
> /*
> len = 0;
> while (len < max_chars && ((const char *) str)[len] != '\0')
> len++;
> */
> len = strnlen(str, max_chars);
strnlen() exists only in Linux and FreeBSD, so if this change is made it has to be behind #ifdef HAVE_STRNLEN. But if it was only p_strdup() that was on the profile listing, it's a bit too much trouble to add support for it.
> I wonder why You use loops instead strlen, which is optimalised on every platforms.
No reason. I guess the excuse is that it was written 8-9 years ago.
More information about the dovecot
mailing list