Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15
STALE3741d

[PATCH] strbuf_write: omit system call when length is zero

From: Stefan Beller <hidden>
Date: 2016-06-15 23:08:28
Subsystem: the rest · Maintainer: Linus Torvalds

In case the length of the buffer is zero, we do not need to call the
fwrite system call as a performance improvement.

Signed-off-by: Stefan Beller <redacted>
---

 This applies on top of v17 for origin/sb/submodule-parallel-update.
 
 In case there are other reasons for origin/sb/submodule-parallel-update
 to need a reroll I'll squash it in. But as this is a pure performance
 optimization in a case we are not running into with that series and that
 series is clashing with Davids refs backend series, I figure we may not
 want to have a reroll for this fix alone.
 
 Thanks,
 Stefan
  

 strbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/strbuf.c b/strbuf.c
index 71345cd..5f6da82 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -397,7 +397,7 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
 
 ssize_t strbuf_write(struct strbuf *sb, FILE *f)
 {
-	return fwrite(sb->buf, 1, sb->len, f);
+	return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0;
 }
 
 
-- 
2.7.2.374.ga5f0819.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help