From: Pierre Habouzit <madcoder@debian.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 5/5] Avoid duplicating memory, and use xmemdupz instead of xstrdup.
Date: Tue, 18 Sep 2007 23:48:22 +0200 [thread overview]
Message-ID: <20070918224123.3251C344AB3@madism.org> (raw)
In-Reply-To: <20070918223947.GB4535@artemis.corp>
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
fetch.c | 23 +++++++++--------------
1 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/fetch.c b/fetch.c
index b1c1f07..479ec02 100644
--- a/fetch.c
+++ b/fetch.c
@@ -218,24 +218,19 @@ int pull_targets_stdin(char ***target, const char ***write_ref)
struct strbuf buf;
*target = NULL; *write_ref = NULL;
strbuf_init(&buf, 0);
- while (1) {
- char *rf_one = NULL;
- char *tg_one;
-
- if (strbuf_getline(&buf, stdin, '\n') == EOF)
- break;
- tg_one = buf.buf;
- rf_one = strchr(tg_one, '\t');
- if (rf_one)
- *rf_one++ = 0;
+ while (strbuf_getline(&buf, stdin, '\n') != EOF) {
+ char *rf_one = memchr(buf.buf, '\t', buf.len);
if (targets >= targets_alloc) {
- targets_alloc = targets_alloc ? targets_alloc * 2 : 64;
- *target = xrealloc(*target, targets_alloc * sizeof(**target));
+ ALLOC_GROW(target, targets, targets_alloc);
*write_ref = xrealloc(*write_ref, targets_alloc * sizeof(**write_ref));
}
- (*target)[targets] = xstrdup(tg_one);
- (*write_ref)[targets] = rf_one ? xstrdup(rf_one) : NULL;
+ if (rf_one) {
+ (*write_ref)[targets] = xmemdupz(rf_one, buf.len - (rf_one - buf.buf));
+ } else {
+ (*write_ref)[targets] = NULL;
+ }
+ (*target)[targets] = strbuf_detach(&buf);
targets++;
}
strbuf_release(&buf);
--
1.5.3.1
next prev parent reply other threads:[~2007-09-18 22:42 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-18 22:39 let's refactor quoting Pierre Habouzit
2007-09-18 17:18 ` [PATCH 1/5] strbuf API additions and enhancements Pierre Habouzit
2007-09-19 12:46 ` Edgar Toernig
2007-09-19 13:36 ` Pierre Habouzit
2007-09-19 18:46 ` Junio C Hamano
2007-09-20 6:17 ` Johannes Sixt
2007-09-20 7:20 ` Kalle Olavi Niemitalo
2007-09-20 16:10 ` Jeff King
2007-09-18 20:15 ` [PATCH 2/5] sq_quote_argv and add_to_string rework with strbuf's Pierre Habouzit
2007-09-19 8:09 ` Junio C Hamano
2007-09-19 8:23 ` Pierre Habouzit
2007-09-18 21:22 ` [PATCH 3/5] Rework unquote_c_style to work on a strbuf Pierre Habouzit
2007-09-19 0:14 ` Pierre Habouzit
2007-09-19 8:09 ` Junio C Hamano
2007-09-19 8:22 ` Pierre Habouzit
2007-09-18 21:48 ` Pierre Habouzit [this message]
2007-09-18 22:00 ` [PATCH 4/5] Full rework of quote_c_style and write_name_quoted Pierre Habouzit
2007-09-19 0:07 ` Pierre Habouzit
2007-09-19 0:55 ` Junio C Hamano
2007-09-19 1:14 ` Pierre Habouzit
2007-09-19 6:37 ` Andreas Ericsson
2007-09-19 8:00 ` Pierre Habouzit
2007-09-19 8:08 ` Andreas Ericsson
2007-09-19 8:21 ` Pierre Habouzit
2007-09-19 8:28 ` David Kastrup
2007-09-19 8:31 ` Junio C Hamano
2007-09-19 8:38 ` David Kastrup
2007-09-19 8:28 ` Junio C Hamano
2007-09-19 8:47 ` Pierre Habouzit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070918224123.3251C344AB3@madism.org \
--to=madcoder@debian.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).