diff options
author | Max Kellermann <max@duempel.org> | 2011-10-10 10:14:55 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-10-10 10:24:06 +0200 |
commit | 08a0bb756d34bcff50cf70b9aa1ab5c2ae77a1ea (patch) | |
tree | 7b9789e05303feb8375fdedb6fdc64b2f9d14304 /src | |
parent | 20c6159c041cc5ec644c51009503cf6801b6fcab (diff) | |
download | mpd-08a0bb756d34bcff50cf70b9aa1ab5c2ae77a1ea.tar.gz mpd-08a0bb756d34bcff50cf70b9aa1ab5c2ae77a1ea.tar.xz mpd-08a0bb756d34bcff50cf70b9aa1ab5c2ae77a1ea.zip |
pcm_byteswap: use "end" pointer instead of buffer size
Diffstat (limited to '')
-rw-r--r-- | src/pcm_byteswap.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/pcm_byteswap.c b/src/pcm_byteswap.c index 13ed85bfe..fcd995ba2 100644 --- a/src/pcm_byteswap.c +++ b/src/pcm_byteswap.c @@ -31,13 +31,16 @@ const int16_t *pcm_byteswap_16(struct pcm_buffer *buffer, const int16_t *src, size_t len) { - unsigned i; int16_t *buf = pcm_buffer_get(buffer, len); assert(buf != NULL); - for (i = 0; i < len / 2; i++) - buf[i] = GUINT16_SWAP_LE_BE(src[i]); + const int16_t *src_end = src + len / sizeof(*src); + int16_t *dest = buf; + while (src < src_end) { + const int16_t x = *src++; + *dest++ = GUINT16_SWAP_LE_BE(x); + } return buf; } @@ -45,13 +48,16 @@ const int16_t *pcm_byteswap_16(struct pcm_buffer *buffer, const int32_t *pcm_byteswap_32(struct pcm_buffer *buffer, const int32_t *src, size_t len) { - unsigned i; int32_t *buf = pcm_buffer_get(buffer, len); assert(buf != NULL); - for (i = 0; i < len / 4; i++) - buf[i] = GUINT32_SWAP_LE_BE(src[i]); + const int32_t *src_end = src + len / sizeof(*src); + int32_t *dest = buf; + while (src < src_end) { + const int32_t x = *src++; + *dest++ = GUINT32_SWAP_LE_BE(x); + } return buf; } |