Module Name: src Committed By: rillig Date: Thu Aug 13 04:25:09 UTC 2020
Modified Files: src/usr.bin/make: buf.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/buf.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/buf.h diff -u src/usr.bin/make/buf.h:1.24 src/usr.bin/make/buf.h:1.25 --- src/usr.bin/make/buf.h:1.24 Thu Aug 13 04:12:13 2020 +++ src/usr.bin/make/buf.h Thu Aug 13 04:25:09 2020 @@ -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 @@ typedef struct Buffer { #define __predict_false(x) (x) #endif -/* 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) - -#define BUF_ERROR 256 +void Buf_Expand_1(Buffer *); -#define Buf_Size(bp) ((bp)->count) +/* Buf_AddByte adds a single byte to a buffer. */ +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; +} + +static inline size_t +Buf_Size(const Buffer *bp) +{ + return 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 *);