Linux-Sparse Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] predef: simplify add_pre_buffer()
@ 2020-07-05 10:29 Luc Van Oostenryck
  0 siblings, 0 replies; only message in thread
From: Luc Van Oostenryck @ 2020-07-05 10:29 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

pre_buffer_begin & pre_buffer_end are the head and the tail of
a singly chained list. As such, it's slightly easier to not
keep a pointer on the last element but a pointer where the
next element should be written.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/lib.c b/lib.c
index e56788260cb7..863900b54c3c 100644
--- a/lib.c
+++ b/lib.c
@@ -248,7 +248,7 @@ void die(const char *fmt, ...)
 }
 
 static struct token *pre_buffer_begin = NULL;
-static struct token *pre_buffer_end = NULL;
+static struct token **pre_buffer_next = &pre_buffer_begin;
 
 int Waddress = 0;
 int Waddress_space = 1;
@@ -348,11 +348,8 @@ void add_pre_buffer(const char *fmt, ...)
 	size = vsnprintf(buffer, sizeof(buffer), fmt, args);
 	va_end(args);
 	begin = tokenize_buffer(buffer, size, &end);
-	if (!pre_buffer_begin)
-		pre_buffer_begin = begin;
-	if (pre_buffer_end)
-		pre_buffer_end->next = begin;
-	pre_buffer_end = end;
+	*pre_buffer_next = begin;
+	pre_buffer_next = &end->next;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-- 
2.27.0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-05 10:29 [PATCH] predef: simplify add_pre_buffer() Luc Van Oostenryck

Linux-Sparse Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sparse/0 linux-sparse/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sparse linux-sparse/ https://lore.kernel.org/linux-sparse \
		linux-sparse@vger.kernel.org
	public-inbox-index linux-sparse

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sparse


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git