From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Carlos Rica <jasampler@gmail.com>
Cc: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
"Kristian Høgsberg" <krh@redhat.com>
Subject: Re: [PATCH 1/2] Function stripspace now gets a buffer instead file descriptors.
Date: Wed, 11 Jul 2007 20:17:06 +0100 (BST) [thread overview]
Message-ID: <Pine.LNX.4.64.0707112010560.4516@racer.site> (raw)
In-Reply-To: <4695267A.7080202@gmail.com>
Hi,
On Wed, 11 Jul 2007, Carlos Rica wrote:
> @@ -28,52 +26,67 @@ static int cleanup(char *line, int len)
> * Remove empty lines from the beginning and end
> * and also trailing spaces from every line.
> *
> + * Note that the buffer will not be null-terminated.
> + *
> * Turn multiple consecutive empty lines between paragraphs
> * into just one empty line.
> *
> * If the input has only empty lines and spaces,
> * no output will be produced.
> *
> + * If last line has a newline at the end, it will be removed.
> + *
Please let me comment about the rationale for both changes: The
stripspace() function (which this hunk is about) is more useful if it does
not allocate a new buffer, but works in-place.
And since it knows the new length already, it can just as well return the
length, and _not_ NUL terminate (which would mean that we have to
reallocate if we used read_pipe() to get the buffer).
The reason for the missing newline at the end is the same: since we accept
buffers with a missing newline at the end, we would have to reallocate in
that case.
So for the sake of simplicity, we neither NUL-terminate, nor \n terminate
the buffer, and leave that to the callers.
Ciao,
Dscho
next prev parent reply other threads:[~2007-07-11 19:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-11 18:50 [PATCH 1/2] Function stripspace now gets a buffer instead file descriptors Carlos Rica
2007-07-11 19:17 ` Johannes Schindelin [this message]
2007-07-11 22:24 ` Junio C Hamano
2007-07-11 23:20 ` Bill Lear
2007-07-11 23:41 ` Carlos Rica
2007-07-12 0:03 ` Junio C Hamano
2007-07-12 0:14 ` Carlos Rica
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0707112010560.4516@racer.site \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jasampler@gmail.com \
--cc=krh@redhat.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.
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).