]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] buffers: inline buffer_si_putchar()
authorWilly Tarreau <w@1wt.eu>
Sun, 13 Sep 2009 12:58:00 +0000 (14:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 19 Sep 2009 14:34:18 +0000 (16:34 +0200)
By inlining this function and slightly reordering it, we can double
the getchar/putchar test throughput, and reduce its footprint by about
40 bytes. Also, it was the only non-inlined char-based function, which
now makes it more consistent this time.

include/proto/buffers.h
src/buffers.c

index 3cde2092272e96ba23f74bdaf5d30970bfc6c238..66bee89057de74c5fd6a1e918e9d4f6bda3c42cd 100644 (file)
@@ -389,6 +389,40 @@ static inline int buffer_si_peekchar(struct buffer *buf)
                return -2;
 }
 
+/* Try to write character <c> into buffer <buf> after length controls. This
+ * work like buffer_feed(buf, &c, 1).
+ * Returns non-zero in case of success, 0 if the buffer was full.
+ * The send limit is automatically adjusted with the amount of data written.
+ */
+static inline int buffer_si_putchar(struct buffer *buf, char c)
+{
+       if (buf->flags & BF_FULL)
+               return 0;
+
+       if (buf->flags & BF_EMPTY) {
+               buf->flags &= ~BF_EMPTY;
+               buf->r = buf->w = buf->lr = buf->data;
+       }
+
+       *buf->r = c;
+
+       buf->l++;
+       if (buf->l >= buf->max_len)
+               buf->flags |= BF_FULL;
+
+       buf->r++;
+       if (buf->r - buf->data == buf->size)
+               buf->r -= buf->size;
+
+       if ((signed)(buf->to_forward - 1) >= 0) {
+               buf->to_forward--;
+               buf->send_max++;
+       }
+
+       buf->total++;
+       return 1;
+}
+
 int buffer_write(struct buffer *buf, const char *msg, int len);
 int buffer_feed(struct buffer *buf, const char *str, int len);
 int buffer_si_putchar(struct buffer *buf, char c);
index ee7a5dce7588b6f94c0148aade65618085156ca4..edda45954fa0227e2001fac357b8359632d01267 100644 (file)
@@ -119,38 +119,6 @@ int buffer_feed(struct buffer *buf, const char *str, int len)
        return -1;
 }
 
-/* Try to write character <c> into buffer <buf> after length controls. This
- * work like buffer_feed(buf, &c, 1).
- * Returns non-zero in case of success, 0 if the buffer was full.
- * The send limit is automatically adjusted with the amount of data written.
- */
-int buffer_si_putchar(struct buffer *buf, char c)
-{
-       if (buf->flags & BF_FULL)
-               return 0;
-
-       if (!buf->l)
-               buf->r = buf->w = buf->lr = buf->data;
-
-       *buf->r++ = c;
-       buf->l++;
-       buf->total++;
-
-       if (buf->to_forward) {
-               buf->send_max++;
-               buf->to_forward--;
-       }
-
-       if (buf->r == buf->data + buf->size)
-               buf->r = buf->data;
-
-       buf->flags &= ~(BF_EMPTY|BF_FULL);
-       if (buf->l >= buf->max_len)
-               buf->flags |= BF_FULL;
-
-       return 1;
-}
-
 /* Get one text line out of a buffer from a stream interface.
  * Return values :
  *   >0 : number of bytes read. Includes the \n if present before len or end.