Commit 0579e022 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Optimize vlc_memstream_puts() with constant string

If the string given to vlc_memstream_puts() is constant, or at least
its length is constant, use vlc_memstream_write() instead and let GCC
compute the length at build-time.
parent 0f16e431
......@@ -62,4 +62,15 @@ VLC_API
int vlc_memstream_printf(struct vlc_memstream *s, const char *fmt,
...) VLC_FORMAT(2,3);
# ifdef __GNUC__
static inline int vlc_memstream_puts_len(struct vlc_memstream *ms,
const char *str, size_t len)
{
return (vlc_memstream_write(ms, str, len) == len) ? (int)len : EOF;
}
# define vlc_memstream_puts(ms,s) \
(__builtin_constant_p(__builtin_strlen(s)) ? \
vlc_memstream_puts_len(ms,s,__builtin_strlen(s)) : \
vlc_memstream_puts(ms,s))
# endif
#endif /* VLC_MEMSTREAM_H */
......@@ -82,7 +82,7 @@ int vlc_memstream_putc(struct vlc_memstream *ms, int c)
return fputc(c, ms->stream);
}
int vlc_memstream_puts(struct vlc_memstream *ms, const char *str)
int (vlc_memstream_puts)(struct vlc_memstream *ms, const char *str)
{
if (unlikely(ms->stream == NULL))
return EOF;
......@@ -145,7 +145,7 @@ int vlc_memstream_putc(struct vlc_memstream *ms, int c)
return (vlc_memstream_write(ms, &(unsigned char){ c }, 1u) == 1) ? c : EOF;
}
int vlc_memstream_puts(struct vlc_memstream *ms, const char *str)
int (vlc_memstream_puts)(struct vlc_memstream *ms, const char *str)
{
size_t len = strlen(str);
return (vlc_memstream_write(ms, str, len) == len) ? 0 : EOF;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment