diff options
author | Zachary T Welch <zw@superlucidity.net> | 2009-11-14 08:19:24 -0800 |
---|---|---|
committer | Zachary T Welch <zw@superlucidity.net> | 2009-11-16 00:46:33 -0800 |
commit | 5a43bd2e185bf469561a8370dcd543cc4813c33f (patch) | |
tree | e2167a12e6507090a3ef6c70a874fd7c86a31586 | |
parent | 82fc2f9628e0f1dbd9010e0146ff63832e4a77a1 (diff) | |
download | openocd_libswd-5a43bd2e185bf469561a8370dcd543cc4813c33f.tar.gz openocd_libswd-5a43bd2e185bf469561a8370dcd543cc4813c33f.tar.bz2 openocd_libswd-5a43bd2e185bf469561a8370dcd543cc4813c33f.tar.xz openocd_libswd-5a43bd2e185bf469561a8370dcd543cc4813c33f.zip |
binarybuffer: move variables to point of first use
Reduce some noise from subsequent patches.
-rw-r--r-- | src/helper/binarybuffer.c | 31 | ||||
-rw-r--r-- | src/helper/binarybuffer.h | 6 |
2 files changed, 9 insertions, 28 deletions
diff --git a/src/helper/binarybuffer.c b/src/helper/binarybuffer.c index d813ecf5..95e084ef 100644 --- a/src/helper/binarybuffer.c +++ b/src/helper/binarybuffer.c @@ -50,13 +50,10 @@ const unsigned char bit_reverse_table256[] = uint8_t* buf_cpy(const uint8_t *from, uint8_t *to, int size) { - unsigned int num_bytes = CEIL(size, 8); - unsigned int i; - if (from == NULL) return NULL; - for (i = 0; i < num_bytes; i++) + for (unsigned i = 0, num_bytes = CEIL(size, 8); i < num_bytes; i++) to[i] = from[i]; /* mask out bits that don't belong to the buffer */ @@ -70,13 +67,10 @@ uint8_t* buf_cpy(const uint8_t *from, uint8_t *to, int size) int buf_cmp(const uint8_t *buf1, const uint8_t *buf2, int size) { - int num_bytes = CEIL(size, 8); - int i; - if (!buf1 || !buf2) return 1; - for (i = 0; i < num_bytes; i++) + for (unsigned i = 0, num_bytes = CEIL(size, 8); i < num_bytes; i++) { /* last byte */ /* mask out bits that don't really belong to the buffer if size isn't a multiple of 8 bits */ @@ -97,10 +91,7 @@ int buf_cmp(const uint8_t *buf1, const uint8_t *buf2, int size) int buf_cmp_mask(const uint8_t *buf1, const uint8_t *buf2, const uint8_t *mask, int size) { - int num_bytes = CEIL(size, 8); - int i; - - for (i = 0; i < num_bytes; i++) + for (unsigned i = 0, num_bytes = CEIL(size, 8); i < num_bytes; i++) { /* last byte */ /* mask out bits that don't really belong to the buffer if size isn't a multiple of 8 bits */ @@ -122,10 +113,7 @@ int buf_cmp_mask(const uint8_t *buf1, const uint8_t *buf2, const uint8_t *mask, uint8_t* buf_set_ones(uint8_t *buf, int count) { - int num_bytes = CEIL(count, 8); - int i; - - for (i = 0; i < num_bytes; i++) + for (unsigned i = 0, num_bytes = CEIL(count, 8); i < num_bytes; i++) { if (count >= 8) buf[i] = 0xff; @@ -141,9 +129,8 @@ uint8_t* buf_set_ones(uint8_t *buf, int count) uint8_t* buf_set_buf(const uint8_t *src, int src_start, uint8_t *dst, int dst_start, int len) { int src_idx = src_start, dst_idx = dst_start; - int i; - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { if (((src[src_idx / 8] >> (src_idx % 8)) & 1) == 1) dst[dst_idx / 8] |= 1 << (dst_idx % 8); @@ -158,9 +145,7 @@ uint8_t* buf_set_buf(const uint8_t *src, int src_start, uint8_t *dst, int dst_st uint32_t flip_u32(uint32_t value, unsigned int num) { - uint32_t c; - - c = (bit_reverse_table256[value & 0xff] << 24) | + uint32_t c = (bit_reverse_table256[value & 0xff] << 24) | (bit_reverse_table256[(value >> 8) & 0xff] << 16) | (bit_reverse_table256[(value >> 16) & 0xff] << 8) | (bit_reverse_table256[(value >> 24) & 0xff]); @@ -173,12 +158,10 @@ uint32_t flip_u32(uint32_t value, unsigned int num) int ceil_f_to_u32(float x) { - uint32_t y; - if (x < 0) /* return zero for negative numbers */ return 0; - y = x; /* cut off fraction */ + uint32_t y = x; /* cut off fraction */ if ((x - y) > 0.0) /* if there was a fractional part, increase by one */ y++; diff --git a/src/helper/binarybuffer.h b/src/helper/binarybuffer.h index 60077b31..400cbbe6 100644 --- a/src/helper/binarybuffer.h +++ b/src/helper/binarybuffer.h @@ -39,8 +39,7 @@ static inline void buf_set_u32(uint8_t* buffer, buffer[1] = (value >> 8) & 0xff; buffer[0] = (value >> 0) & 0xff; } else { - unsigned int i; - for (i = first; i < first + num; i++) + for (unsigned i = first; i < first + num; i++) { if (((value >> (i - first)) & 1) == 1) buffer[i / 8] |= 1 << (i % 8); @@ -59,8 +58,7 @@ static inline uint32_t buf_get_u32(const uint8_t* buffer, (((uint32_t)buffer[0]) << 0); } else { uint32_t result = 0; - unsigned int i; - for (i = first; i < first + num; i++) + for (unsigned i = first; i < first + num; i++) { if (((buffer[i / 8] >> (i % 8)) & 1) == 1) result |= 1 << (i - first); |