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): replace direct access to Buffer fields...



details:   https://anonhg.NetBSD.org/src/rev/00822f542e92
branches:  trunk
changeset: 955360:00822f542e92
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 27 16:10:07 2020 +0000

description:
make(1): replace direct access to Buffer fields with inline function

This way, renaming the fields of the buffer is restricted to only buf.h
and buf.c.

diffstat:

 usr.bin/make/buf.h |  8 +++++++-
 usr.bin/make/var.c |  9 ++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diffs (59 lines):

diff -r c2495c213033 -r 00822f542e92 usr.bin/make/buf.h
--- a/usr.bin/make/buf.h        Sun Sep 27 15:42:48 2020 +0000
+++ b/usr.bin/make/buf.h        Sun Sep 27 16:10:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: buf.h,v 1.29 2020/09/13 15:27:25 rillig Exp $  */
+/*     $NetBSD: buf.h,v 1.30 2020/09/27 16:10:07 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -112,6 +112,12 @@
     return bp->count;
 }
 
+static inline MAKE_ATTR_UNUSED Boolean
+Buf_EndsWith(const Buffer *bp, char ch)
+{
+    return bp->count > 0 && bp->buffer[bp->count - 1] == ch;
+}
+
 void Buf_AddBytes(Buffer *, const char *, size_t);
 void Buf_AddBytesBetween(Buffer *, const char *, const char *);
 void Buf_AddStr(Buffer *, const char *);
diff -r c2495c213033 -r 00822f542e92 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Sep 27 15:42:48 2020 +0000
+++ b/usr.bin/make/var.c        Sun Sep 27 16:10:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.543 2020/09/26 16:00:12 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.544 2020/09/27 16:10:07 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
 #include    "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.543 2020/09/26 16:00:12 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.544 2020/09/27 16:10:07 rillig Exp $");
 
 #define VAR_DEBUG_IF(cond, fmt, ...)   \
     if (!(DEBUG(VAR) && (cond)))       \
@@ -1433,8 +1433,7 @@
              "to \"%s\"\n",
              word, args->tvar, args->str, s);
 
-    if (s[0] == '\n' || (buf->buf.count > 0 &&
-                        buf->buf.buffer[buf->buf.count - 1] == '\n'))
+    if (s[0] == '\n' || Buf_EndsWith(&buf->buf, '\n'))
        buf->needSep = FALSE;
     SepBuf_AddStr(buf, s);
     free(s);
@@ -1552,7 +1551,7 @@
 
     for (i = 0; i < words.len; i++) {
        modifyWord(words.words[i], &result, modifyWord_args);
-       if (result.buf.count > 0)
+       if (Buf_Size(&result.buf) > 0)
            SepBuf_Sep(&result);
     }
 



Home | Main Index | Thread Index | Old Index