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: replace enum bit-set with bit-field
details: https://anonhg.NetBSD.org/src/rev/de5060a660c5
branches: trunk
changeset: 1018411:de5060a660c5
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Feb 02 15:41:14 2021 +0000
description:
make: replace enum bit-set with bit-field
No functional change.
The generated code from GCC 5.5 is very similar. On x86_64, memory
access is no longer in 32-bit units but in 8-bit units since only the
first few bits are actually used. The bit patterns are the same as
before, so if there is any difference in performance, GCC should have
chosen the more efficient variant all along.
In a previous experiment, the code size increased a lot, surprisingly.
diffstat:
usr.bin/make/var.c | 46 +++++++++++++++++++++++-----------------------
1 files changed, 23 insertions(+), 23 deletions(-)
diffs (156 lines):
diff -r d6015e7d76eb -r de5060a660c5 usr.bin/make/var.c
--- a/usr.bin/make/var.c Tue Feb 02 10:48:33 2021 +0000
+++ b/usr.bin/make/var.c Tue Feb 02 15:41:14 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.787 2021/02/01 19:46:58 rillig Exp $ */
+/* $NetBSD: var.c,v 1.788 2021/02/02 15:41:14 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.787 2021/02/01 19:46:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.788 2021/02/02 15:41:14 rillig Exp $");
typedef enum VarFlags {
VAR_NONE = 0,
@@ -223,16 +223,16 @@
} UnexportWhat;
/* Flags for pattern matching in the :S and :C modifiers */
-typedef enum VarPatternFlags {
- VARP_NONE = 0,
+typedef struct VarPatternFlags {
+
/* Replace as often as possible ('g') */
- VARP_SUB_GLOBAL = 1 << 0,
+ Boolean subGlobal: 1;
/* Replace only once ('1') */
- VARP_SUB_ONE = 1 << 1,
+ Boolean subOnce: 1;
/* Match at start of word ('^') */
- VARP_ANCHOR_START = 1 << 2,
+ Boolean anchorStart: 1;
/* Match at end of word ('$') */
- VARP_ANCHOR_END = 1 << 3
+ Boolean anchorEnd: 1;
} VarPatternFlags;
/* SepBuf is a string being built from words, interleaved with separators. */
@@ -1440,15 +1440,15 @@
struct ModifyWord_SubstArgs *args = data;
const char *match;
- if ((args->pflags & VARP_SUB_ONE) && args->matched)
+ if (args->pflags.subOnce && args->matched)
goto nosub;
- if (args->pflags & VARP_ANCHOR_START) {
+ if (args->pflags.anchorStart) {
if (wordLen < args->lhsLen ||
memcmp(word, args->lhs, args->lhsLen) != 0)
goto nosub;
- if ((args->pflags & VARP_ANCHOR_END) && wordLen != args->lhsLen)
+ if ((args->pflags.anchorEnd) && wordLen != args->lhsLen)
goto nosub;
/* :S,^prefix,replacement, or :S,^whole$,replacement, */
@@ -1459,7 +1459,7 @@
return;
}
- if (args->pflags & VARP_ANCHOR_END) {
+ if (args->pflags.anchorEnd) {
const char *start;
if (wordLen < args->lhsLen)
@@ -1486,7 +1486,7 @@
args->matched = TRUE;
wordLen -= (size_t)(match - word) + args->lhsLen;
word += (size_t)(match - word) + args->lhsLen;
- if (wordLen == 0 || !(args->pflags & VARP_SUB_GLOBAL))
+ if (wordLen == 0 || !args->pflags.subGlobal)
break;
}
nosub:
@@ -1527,7 +1527,7 @@
int flags = 0;
regmatch_t m[10];
- if ((args->pflags & VARP_SUB_ONE) && args->matched)
+ if (args->pflags.subOnce && args->matched)
goto nosub;
tryagain:
@@ -1575,7 +1575,7 @@
}
wp += m[0].rm_eo;
- if (args->pflags & VARP_SUB_GLOBAL) {
+ if (args->pflags.subGlobal) {
flags |= REG_NOTBOL;
if (m[0].rm_so == 0 && m[0].rm_eo == 0) {
SepBuf_AddBytes(buf, wp, 1);
@@ -2093,7 +2093,7 @@
if (p[1] == delim) { /* Unescaped $ at end of pattern */
if (out_pflags != NULL)
- *out_pflags |= VARP_ANCHOR_END;
+ out_pflags->anchorEnd = TRUE;
else
Buf_AddByte(&buf, *p);
p++;
@@ -2666,7 +2666,7 @@
*pp += 2;
- args.pflags = VARP_NONE;
+ args.pflags = (VarPatternFlags){ FALSE, FALSE, FALSE, FALSE };
args.matched = FALSE;
/*
@@ -2674,7 +2674,7 @@
* start of the word -- skip over it and flag pattern.
*/
if (**pp == '^') {
- args.pflags |= VARP_ANCHOR_START;
+ args.pflags.anchorStart = TRUE;
(*pp)++;
}
@@ -2694,10 +2694,10 @@
for (;; (*pp)++) {
switch (**pp) {
case 'g':
- args.pflags |= VARP_SUB_GLOBAL;
+ args.pflags.subGlobal = TRUE;
continue;
case '1':
- args.pflags |= VARP_SUB_ONE;
+ args.pflags.subOnce = TRUE;
continue;
case 'W':
oneBigWord = TRUE;
@@ -2745,16 +2745,16 @@
return AMR_CLEANUP;
}
- args.pflags = VARP_NONE;
+ args.pflags = (VarPatternFlags){ FALSE, FALSE, FALSE, FALSE };
args.matched = FALSE;
oneBigWord = st->oneBigWord;
for (;; (*pp)++) {
switch (**pp) {
case 'g':
- args.pflags |= VARP_SUB_GLOBAL;
+ args.pflags.subGlobal = TRUE;
continue;
case '1':
- args.pflags |= VARP_SUB_ONE;
+ args.pflags.subOnce = TRUE;
continue;
case 'W':
oneBigWord = TRUE;
Home |
Main Index |
Thread Index |
Old Index