]> granicus.if.org Git - libevent/commitdiff
Turn the increasingly complex *_CHAIN() macros into functions
authorNick Mathewson <nickm@torproject.org>
Tue, 30 Mar 2010 16:48:56 +0000 (12:48 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 31 Mar 2010 16:50:32 +0000 (12:50 -0400)
buffer.c

index 82acaee0f2960da50e6307ebd5eb9f628c67c5e1..85890ff6007f36cdc65dcc64f0ab59bb20d76125 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -626,53 +626,61 @@ done:
        return result;
 }
 
-#define ZERO_CHAIN(dst) do { \
-               ASSERT_EVBUFFER_LOCKED(dst);    \
-               (dst)->first = NULL;            \
-               (dst)->last = NULL;             \
-               (dst)->last_with_datap = &(dst)->first; \
-               (dst)->total_len = 0;           \
-       } while (0)
-
-#define COPY_CHAIN(dst, src) do { \
-               ASSERT_EVBUFFER_LOCKED(dst);                       \
-               ASSERT_EVBUFFER_LOCKED(src);                       \
-               (dst)->first = (src)->first;                       \
-               if ((src)->last_with_datap == &(src)->first)       \
-                       (dst)->last_with_datap = &(dst)->first;    \
-               else                                                    \
-                       (dst)->last_with_datap = (src)->last_with_datap; \
-               (dst)->last = (src)->last;                         \
-               (dst)->total_len = (src)->total_len;               \
-       } while (0)
-
-#define APPEND_CHAIN(dst, src) do {                                    \
-               ASSERT_EVBUFFER_LOCKED(dst);                            \
-               ASSERT_EVBUFFER_LOCKED(src);                            \
-               (dst)->last->next = (src)->first;                       \
-               if ((src)->last_with_datap == &(src)->first)            \
-                       (dst)->last_with_datap = &(dst)->last->next;    \
-               else                                                    \
-                       (dst)->last_with_datap = (src)->last_with_datap; \
-               (dst)->last = (src)->last;                              \
-               (dst)->total_len += (src)->total_len;                   \
-       } while (0)
-
-#define PREPEND_CHAIN(dst, src) do {                                   \
-               ASSERT_EVBUFFER_LOCKED(dst);                            \
-               ASSERT_EVBUFFER_LOCKED(src);                            \
-               (src)->last->next = (dst)->first;                       \
-               (dst)->first = (src)->first;                            \
-               (dst)->total_len += (src)->total_len;                   \
-               if (*(dst)->last_with_datap == NULL) {                  \
-                       if ((src)->last_with_datap == &(src)->first)    \
-                               (dst)->last_with_datap = &(dst)->first; \
-                       else                                            \
-                               (dst)->last_with_datap = (src)->last_with_datap; \
-               } else if ((dst)->last_with_datap == &(dst)->first) {   \
-                       (dst)->last_with_datap = &(src)->last->next;    \
-               }                                                       \
-       } while (0)
+static inline void
+ZERO_CHAIN(struct evbuffer *dst)
+{
+       ASSERT_EVBUFFER_LOCKED(dst);
+       dst->first = NULL;
+       dst->last = NULL;
+       dst->last_with_datap = &(dst)->first;
+       dst->total_len = 0;
+}
+
+static inline void
+COPY_CHAIN(struct evbuffer *dst, struct evbuffer *src)
+{
+       ASSERT_EVBUFFER_LOCKED(dst);
+       ASSERT_EVBUFFER_LOCKED(src);
+       dst->first = src->first;
+       if (src->last_with_datap == &src->first)
+               dst->last_with_datap = &dst->first;
+       else
+               dst->last_with_datap = src->last_with_datap;
+       dst->last = src->last;
+       dst->total_len = src->total_len;
+}
+
+static void
+APPEND_CHAIN(struct evbuffer *dst, struct evbuffer *src)
+{
+       ASSERT_EVBUFFER_LOCKED(dst);
+       ASSERT_EVBUFFER_LOCKED(src);
+       dst->last->next = src->first;
+       if (src->last_with_datap == &src->first)
+               dst->last_with_datap = &dst->last->next;
+       else
+               dst->last_with_datap = src->last_with_datap;
+       dst->last = src->last;
+       dst->total_len += src->total_len;
+}
+
+static void
+PREPEND_CHAIN(struct evbuffer *dst, struct evbuffer *src)
+{
+       ASSERT_EVBUFFER_LOCKED(dst);
+       ASSERT_EVBUFFER_LOCKED(src);
+       src->last->next = dst->first;
+       dst->first = src->first;
+       dst->total_len += src->total_len;
+       if (*dst->last_with_datap == NULL) {
+               if (src->last_with_datap == &(src)->first)
+                       dst->last_with_datap = &dst->first;
+               else
+                       dst->last_with_datap = src->last_with_datap;
+       } else if (dst->last_with_datap == &dst->first) {
+               dst->last_with_datap = &src->last->next;
+       }
+}
 
 int
 evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf)