Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make(1): convert Buf_AddByte to inline function
details: https://anonhg.NetBSD.org/src/rev/3b1d5f382804
branches: trunk
changeset: 1012869:3b1d5f382804
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Aug 13 04:25:09 2020 +0000
description:
make(1): convert Buf_AddByte to inline function
This lets the compiler decide whether to actually inline the code (which
it does). It also provides better type safety and avoids a few
underscores and parentheses in the code.
diffstat:
usr.bin/make/buf.h | 33 +++++++++++++++++++--------------
1 files changed, 19 insertions(+), 14 deletions(-)
diffs (50 lines):
diff -r 54d0bc24dc5f -r 3b1d5f382804 usr.bin/make/buf.h
--- a/usr.bin/make/buf.h Thu Aug 13 04:12:13 2020 +0000
+++ b/usr.bin/make/buf.h Thu Aug 13 04:25:09 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.h,v 1.24 2020/08/13 04:12:13 rillig Exp $ */
+/* $NetBSD: buf.h,v 1.25 2020/08/13 04:25:09 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,22 +93,27 @@
#define __predict_false(x) (x)
#endif
+void Buf_Expand_1(Buffer *);
+
/* Buf_AddByte adds a single byte to a buffer. */
-#define Buf_AddByte(bp, byte) do { \
- size_t _count = ++(bp)->count; \
- char *_ptr; \
- if (__predict_false(_count >= (bp)->size)) \
- Buf_Expand_1(bp); \
- _ptr = (bp)->buffer + _count; \
- _ptr[-1] = (byte); \
- _ptr[0] = 0; \
- } while (0)
+static inline void
+Buf_AddByte(Buffer *bp, char byte)
+{
+ size_t count = ++bp->count;
+ char *ptr;
+ if (__predict_false(count >= bp->size))
+ Buf_Expand_1(bp);
+ ptr = bp->buffer + count;
+ ptr[-1] = byte;
+ ptr[0] = 0;
+}
-#define BUF_ERROR 256
+static inline size_t
+Buf_Size(const Buffer *bp)
+{
+ return bp->count;
+}
-#define Buf_Size(bp) ((bp)->count)
-
-void Buf_Expand_1(Buffer *);
void Buf_AddBytes(Buffer *, const char *, size_t);
void Buf_AddBytesBetween(Buffer *, const char *, const char *);
void Buf_AddStr(Buffer *, const char *);
Home |
Main Index |
Thread Index |
Old Index