git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/2] strbuf: export strbuf_addchars()
@ 2014-09-07  7:03 René Scharfe
  2014-09-07  7:06 ` [PATCH 2/2] strbuf: use strbuf_addchars() for adding a char multiple times René Scharfe
  2014-09-08 18:32 ` [PATCH 1/2] strbuf: export strbuf_addchars() Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: René Scharfe @ 2014-09-07  7:03 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

Move strbuf_addchars() to strbuf.c, where it belongs, and make it
available for other callers.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 Documentation/technical/api-strbuf.txt | 4 ++++
 strbuf.c                               | 7 +++++++
 strbuf.h                               | 1 +
 utf8.c                                 | 7 -------
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/Documentation/technical/api-strbuf.txt b/Documentation/technical/api-strbuf.txt
index 430302c..cca6543 100644
--- a/Documentation/technical/api-strbuf.txt
+++ b/Documentation/technical/api-strbuf.txt
@@ -160,6 +160,10 @@ then they will free() it.
 
 	Add a single character to the buffer.
 
+`strbuf_addchars`::
+
+	Add a character the specified number of times to the buffer.
+
 `strbuf_insert`::
 
 	Insert data to the given position of the buffer. The remaining contents
diff --git a/strbuf.c b/strbuf.c
index 4d31443..0346e74 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -204,6 +204,13 @@ void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len)
 	strbuf_setlen(sb, sb->len + len);
 }
 
+void strbuf_addchars(struct strbuf *sb, int c, size_t n)
+{
+	strbuf_grow(sb, n);
+	memset(sb->buf + sb->len, c, n);
+	strbuf_setlen(sb, sb->len + n);
+}
+
 void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
 {
 	va_list ap;
diff --git a/strbuf.h b/strbuf.h
index 7bdc1da..652b6c4 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -138,6 +138,7 @@ static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2)
 	strbuf_add(sb, sb2->buf, sb2->len);
 }
 extern void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len);
+extern void strbuf_addchars(struct strbuf *sb, int c, size_t n);
 
 typedef size_t (*expand_fn_t) (struct strbuf *sb, const char *placeholder, void *context);
 extern void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn, void *context);
diff --git a/utf8.c b/utf8.c
index b30790d..6d4d04a 100644
--- a/utf8.c
+++ b/utf8.c
@@ -239,13 +239,6 @@ int is_utf8(const char *text)
 	return 1;
 }
 
-static void strbuf_addchars(struct strbuf *sb, int c, size_t n)
-{
-	strbuf_grow(sb, n);
-	memset(sb->buf + sb->len, c, n);
-	strbuf_setlen(sb, sb->len + n);
-}
-
 static void strbuf_add_indented_text(struct strbuf *buf, const char *text,
 				     int indent, int indent2)
 {
-- 
2.1.0

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

* [PATCH 2/2] strbuf: use strbuf_addchars() for adding a char multiple times
  2014-09-07  7:03 [PATCH 1/2] strbuf: export strbuf_addchars() René Scharfe
@ 2014-09-07  7:06 ` René Scharfe
  2014-09-08 18:32 ` [PATCH 1/2] strbuf: export strbuf_addchars() Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: René Scharfe @ 2014-09-07  7:06 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 graph.c           |  5 ++---
 merge-recursive.c |  4 +---
 pretty.c          | 10 +++-------
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/graph.c b/graph.c
index 6404331..dfb99f6 100644
--- a/graph.c
+++ b/graph.c
@@ -1145,7 +1145,7 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)
 
 static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
 {
-	int i, j;
+	int i;
 
 	if (graph->state != GRAPH_COMMIT) {
 		graph_next_line(graph, sb);
@@ -1169,8 +1169,7 @@ static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
 				strbuf_addch(sb, ' ');
 			else {
 				int num_spaces = ((graph->num_parents - 2) * 2);
-				for (j = 0; j < num_spaces; j++)
-					strbuf_addch(sb, ' ');
+				strbuf_addchars(sb, ' ', num_spaces);
 			}
 		} else {
 			strbuf_write_column(sb, col, '|');
diff --git a/merge-recursive.c b/merge-recursive.c
index 1d332b8..dd657e6 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -163,9 +163,7 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)
 	if (!show(o, v))
 		return;
 
-	strbuf_grow(&o->obuf, o->call_depth * 2 + 2);
-	memset(o->obuf.buf + o->obuf.len, ' ', o->call_depth * 2);
-	strbuf_setlen(&o->obuf, o->obuf.len + o->call_depth * 2);
+	strbuf_addchars(&o->obuf, ' ', o->call_depth * 2);
 
 	va_start(ap, fmt);
 	strbuf_vaddf(&o->obuf, fmt, ap);
diff --git a/pretty.c b/pretty.c
index 44b9f64..5971415 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1395,9 +1395,7 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */
 		 * convert it back to chars
 		 */
 		padding = padding - len + local_sb.len;
-		strbuf_grow(sb, padding);
-		strbuf_setlen(sb, sb_len + padding);
-		memset(sb->buf + sb_len, ' ', sb->len - sb_len);
+		strbuf_addchars(sb, ' ', padding);
 		memcpy(sb->buf + sb_len + offset, local_sb.buf,
 		       local_sb.len);
 	}
@@ -1672,10 +1670,8 @@ void pp_remainder(struct pretty_print_context *pp,
 		first = 0;
 
 		strbuf_grow(sb, linelen + indent + 20);
-		if (indent) {
-			memset(sb->buf + sb->len, ' ', indent);
-			strbuf_setlen(sb, sb->len + indent);
-		}
+		if (indent)
+			strbuf_addchars(sb, ' ', indent);
 		strbuf_add(sb, line, linelen);
 		strbuf_addch(sb, '\n');
 	}
-- 
2.1.0

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

* Re: [PATCH 1/2] strbuf: export strbuf_addchars()
  2014-09-07  7:03 [PATCH 1/2] strbuf: export strbuf_addchars() René Scharfe
  2014-09-07  7:06 ` [PATCH 2/2] strbuf: use strbuf_addchars() for adding a char multiple times René Scharfe
@ 2014-09-08 18:32 ` Junio C Hamano
  2014-09-08 21:36   ` René Scharfe
  1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2014-09-08 18:32 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git Mailing List

René Scharfe <l.s.r@web.de> writes:

> Move strbuf_addchars() to strbuf.c, where it belongs, and make it
> available for other callers.
>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>

Wow, fixing up v1.7.0.2~9^2~2?

Both patches look correct, but I have to wonder where you are
drawing these clean-up opportunities from?  Almost as if reading
through dormant part of the codebase one of your hobbies or
something ;-)

Jokes aside, I very much appreciate it.  Thanks.

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

* Re: [PATCH 1/2] strbuf: export strbuf_addchars()
  2014-09-08 18:32 ` [PATCH 1/2] strbuf: export strbuf_addchars() Junio C Hamano
@ 2014-09-08 21:36   ` René Scharfe
  0 siblings, 0 replies; 4+ messages in thread
From: René Scharfe @ 2014-09-08 21:36 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

Am 08.09.2014 um 20:32 schrieb Junio C Hamano:
> René Scharfe <l.s.r@web.de> writes:
>
>> Move strbuf_addchars() to strbuf.c, where it belongs, and make it
>> available for other callers.
>>
>> Signed-off-by: Rene Scharfe <l.s.r@web.de>
>
> Wow, fixing up v1.7.0.2~9^2~2?

About time, isn't it? ;)

> Both patches look correct, but I have to wonder where you are
> drawing these clean-up opportunities from?  Almost as if reading
> through dormant part of the codebase one of your hobbies or
> something ;-)

That, and I'm sitting on a pile of cleanup patches that grew whenever I 
looked at some piece of code for the first time, e.g. due to bug 
reports, or when I took a static analyzer for a test drive etc.  I'm 
trying to filter out the good ones and to send them at opportune moments 
in order to avoid conflicts with real changes.

René

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-07  7:03 [PATCH 1/2] strbuf: export strbuf_addchars() René Scharfe
2014-09-07  7:06 ` [PATCH 2/2] strbuf: use strbuf_addchars() for adding a char multiple times René Scharfe
2014-09-08 18:32 ` [PATCH 1/2] strbuf: export strbuf_addchars() Junio C Hamano
2014-09-08 21:36   ` René Scharfe

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).