summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2020-01-13 13:54:45 +0000
committerMarc Espie <espie@cvs.openbsd.org>2020-01-13 13:54:45 +0000
commit42ccb3b3ba91909414a8f56958ad225f6f1c4e57 (patch)
treea866b04b3feee02a1bae7e7420a5272550901561 /usr.bin/make
parent9545d3c8a3c72662910d613017af66ec1036ee8d (diff)
introduce a "Buf_Reinit" function for handling static buffers that can
be reused throughout running make. Instead of recreating buffers of dubious appropriate size, have one single buffer for various stages of parsing.
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/arch.c7
-rw-r--r--usr.bin/make/buf.c11
-rw-r--r--usr.bin/make/buf.h5
-rw-r--r--usr.bin/make/parse.c14
4 files changed, 23 insertions, 14 deletions
diff --git a/usr.bin/make/arch.c b/usr.bin/make/arch.c
index b87bd7394c7..6cddefb06c8 100644
--- a/usr.bin/make/arch.c
+++ b/usr.bin/make/arch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arch.c,v 1.90 2019/12/21 15:29:25 espie Exp $ */
+/* $OpenBSD: arch.c,v 1.91 2020/01/13 13:54:44 espie Exp $ */
/* $NetBSD: arch.c,v 1.17 1996/11/06 17:58:59 christos Exp $ */
/*
@@ -195,11 +195,10 @@ bool
Arch_ParseArchive(const char **line, Lst nodes, SymTable *ctxt)
{
bool result;
- BUFFER expand;
+ static BUFFER expand;
- Buf_Init(&expand, MAKE_BSIZE);
+ Buf_Reinit(&expand, MAKE_BSIZE);
result = parse_archive(&expand, line, nodes, ctxt);
- Buf_Destroy(&expand);
return result;
}
diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c
index f5e3f8bd9b9..17365935fa6 100644
--- a/usr.bin/make/buf.c
+++ b/usr.bin/make/buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.c,v 1.28 2019/12/21 15:26:47 espie Exp $ */
+/* $OpenBSD: buf.c,v 1.29 2020/01/13 13:54:44 espie Exp $ */
/* $NetBSD: buf.c,v 1.9 1996/12/31 17:53:21 christos Exp $ */
/*
@@ -154,6 +154,15 @@ Buf_printf(Buffer bp, const char *fmt, ...)
}
void
+Buf_Reinit(Buffer bp, size_t size)
+{
+ if (bp->buffer == NULL)
+ Buf_Init(bp, size);
+ else
+ Buf_Reset(bp);
+}
+
+void
Buf_Init(Buffer bp, size_t size)
{
#ifdef STATS_BUF
diff --git a/usr.bin/make/buf.h b/usr.bin/make/buf.h
index 6a31142b289..9be4ed42309 100644
--- a/usr.bin/make/buf.h
+++ b/usr.bin/make/buf.h
@@ -1,7 +1,7 @@
#ifndef _BUF_H
#define _BUF_H
-/* $OpenBSD: buf.h,v 1.23 2019/12/21 15:26:47 espie Exp $ */
+/* $OpenBSD: buf.h,v 1.24 2020/01/13 13:54:44 espie Exp $ */
/* $NetBSD: buf.h,v 1.7 1996/12/31 17:53:22 christos Exp $ */
/*
@@ -106,6 +106,9 @@ extern void Buf_AddChars(Buffer, size_t, const char *);
* Initializes a buffer, to hold approximately init chars.
* Set init to 0 if you have no idea. */
extern void Buf_Init(Buffer, size_t);
+/* Buf_Reinit(buf, init);
+ * Initializes/reset a static buffer */
+extern void Buf_Reinit(Buffer, size_t);
/* Buf_Destroy(buf);
* Nukes a buffer and all its resources. */
#define Buf_Destroy(bp) ((void)free((bp)->buffer))
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index f8732ccf124..d64c289481d 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.125 2020/01/13 13:50:41 espie Exp $ */
+/* $OpenBSD: parse.c,v 1.126 2020/01/13 13:54:44 espie Exp $ */
/* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */
/*
@@ -1641,12 +1641,12 @@ Parse_File(const char *filename, FILE *stream)
bool expectingCommands = false;
bool commands_seen = false;
- /* somewhat permanent spaces to shave time */
- BUFFER buf;
- BUFFER copy;
+ /* permanent spaces to shave time */
+ static BUFFER buf;
+ static BUFFER copy;
- Buf_Init(&buf, MAKE_BSIZE);
- Buf_Init(&copy, MAKE_BSIZE);
+ Buf_Reinit(&buf, MAKE_BSIZE);
+ Buf_Reinit(&copy, MAKE_BSIZE);
Parse_FromFile(filename, stream);
do {
@@ -1686,8 +1686,6 @@ Parse_File(const char *filename, FILE *stream)
Cond_End();
Parse_ReportErrors();
- Buf_Destroy(&buf);
- Buf_Destroy(&copy);
}
void