util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/4] column: Call mbs_to_wcs("") only once
@ 2020-09-20 13:08 Lennard Hofmann
  2020-09-20 13:08 ` [PATCH 3/4] column: Deprecate --table-empty-lines in favor of --keep-empty-lines Lennard Hofmann
  2020-09-20 13:08 ` [PATCH 4/4] tests: column --keep-empty-lines in cols mode Lennard Hofmann
  0 siblings, 2 replies; 4+ messages in thread
From: Lennard Hofmann @ 2020-09-20 13:08 UTC (permalink / raw)
  To: util-linux; +Cc: Lennard Hofmann

Signed-off-by: Lennard Hofmann <lennard.hofmann@web.de>
---
This is an optional patch to improve performance slightly while only
adding three lines of code.
 text-utils/column.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/text-utils/column.c b/text-utils/column.c
index bc7851472..d83d8d6d7 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -496,14 +496,18 @@ static void add_entry(struct column_control *ctl, size_t *maxents, wchar_t *wcs)
 	ctl->ents[ctl->nents] = wcs;
 }

-static void add_empty_entry(struct column_control *ctl, size_t *maxents)
+static void add_empty_entry(struct column_control *ctl, size_t *maxents,
+                            wchar_t *empty)
 {
-	add_entry(ctl, maxents, mbs_to_wcs(""));
+	if (empty == NULL)
+		empty = mbs_to_wcs("");
+	add_entry(ctl, maxents, empty);
 	ctl->nents++;
 }

 static int read_input(struct column_control *ctl, FILE *fp)
 {
+	wchar_t *empty = NULL;
 	char *buf = NULL;
 	size_t bufsz = 0;
 	size_t maxents = 0;
@@ -531,7 +535,7 @@ static int read_input(struct column_control *ctl, FILE *fp)
 				if (ctl->mode == COLUMN_MODE_TABLE)
 					add_emptyline_to_table(ctl);
 				else
-					add_empty_entry(ctl, &maxents);
+					add_empty_entry(ctl, &maxents, empty);
 			}
 			continue;
 		}
--
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-21 13:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-20 13:08 [PATCH 2/4] column: Call mbs_to_wcs("") only once Lennard Hofmann
2020-09-20 13:08 ` [PATCH 3/4] column: Deprecate --table-empty-lines in favor of --keep-empty-lines Lennard Hofmann
2020-09-21 13:08   ` Karel Zak
2020-09-20 13:08 ` [PATCH 4/4] tests: column --keep-empty-lines in cols mode Lennard Hofmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).