summaryrefslogtreecommitdiff
path: root/usr.bin/make/make_malloc.h
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2020-08-01 09:55:00 +0000
committerrillig <rillig@NetBSD.org>2020-08-01 09:55:00 +0000
commit15054899595af6c828883b7a7b5cc97dd6b0303a (patch)
tree2f48f329eee7b6a6b75c6f899ec50e80437e3d58 /usr.bin/make/make_malloc.h
parentb5102f5b4823ceb37f4cb1595236e3958c17ee7a (diff)
make(1): avoid calls to free(3) in the common case of a NULL pointer
Diffstat (limited to 'usr.bin/make/make_malloc.h')
-rw-r--r--usr.bin/make/make_malloc.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/usr.bin/make/make_malloc.h b/usr.bin/make/make_malloc.h
index 36d3eff3c02..350ca2f7b47 100644
--- a/usr.bin/make/make_malloc.h
+++ b/usr.bin/make/make_malloc.h
@@ -1,4 +1,4 @@
-/* $NetBSD: make_malloc.h,v 1.4 2009/01/24 14:43:29 dsl Exp $ */
+/* $NetBSD: make_malloc.h,v 1.5 2020/08/01 09:55:00 rillig Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -39,3 +39,15 @@ char *bmake_strndup(const char *, size_t);
#define bmake_strndup(x,y) estrndup(x,y)
#endif
+/* Thin wrapper around free(3) to avoid the extra function call in case
+ * p is NULL, which on x86_64 costs about 12 machine instructions.
+ * Other platforms are similarly affected.
+ *
+ * The case of a NULL pointer happens especially often after Var_Value,
+ * since only environment variables need to be freed, but not others. */
+static inline void
+bmake_free(void *p)
+{
+ if (p != NULL)
+ free(p);
+}