<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/strbuf.c, branch v2.5.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.5.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.5.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2015-09-04T02:17:50Z</updated>
<entry>
<title>Merge branch 'jh/strbuf-read-use-read-in-full' into maint</title>
<updated>2015-09-04T02:17:50Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-09-04T02:17:50Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=8b2707101aa52d4da98becea0aa910de13768488'/>
<id>urn:sha1:8b2707101aa52d4da98becea0aa910de13768488</id>
<content type='text'>
strbuf_read() used to have one extra iteration (and an unnecessary
strbuf_grow() of 8kB), which was eliminated.

* jh/strbuf-read-use-read-in-full:
  strbuf_read(): skip unnecessary strbuf_grow() at eof
</content>
</entry>
<entry>
<title>strbuf_read(): skip unnecessary strbuf_grow() at eof</title>
<updated>2015-08-10T19:51:13Z</updated>
<author>
<name>Jim Hill</name>
<email>gjthill@gmail.com</email>
</author>
<published>2015-05-31T18:16:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3ebbd00cf3c5a7c6f90e2fed8adaf0c5145fb4ac'/>
<id>urn:sha1:3ebbd00cf3c5a7c6f90e2fed8adaf0c5145fb4ac</id>
<content type='text'>
The loop in strbuf_read() uses xread() repeatedly while extending
the strbuf until the call returns zero.  If the buffer is
sufficiently large to begin with, this results in xread()
returning the remainder of the file to the end (returning
non-zero), the loop extending the strbuf, and then making another
call to xread() to have it return zero.

By using read_in_full(), we can tell when the read reached the end
of file: when it returns less than was requested, it's eof.  This
way we can avoid an extra iteration that allocates an extra 8kB
that is never used.

Signed-off-by: Jim Hill &lt;gjthill@gmail.com&gt;
Reviewed-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'mh/strbuf-read-file-returns-ssize-t'</title>
<updated>2015-07-13T21:00:27Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-07-13T21:00:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d790ba92cc534127fc4c0d58a901d1553835aa62'/>
<id>urn:sha1:d790ba92cc534127fc4c0d58a901d1553835aa62</id>
<content type='text'>
Avoid possible ssize_t to int truncation.

* mh/strbuf-read-file-returns-ssize-t:
  strbuf: strbuf_read_file() should return ssize_t
</content>
</entry>
<entry>
<title>strbuf: strbuf_read_file() should return ssize_t</title>
<updated>2015-07-04T01:25:02Z</updated>
<author>
<name>Michael Haggerty</name>
<email>mhagger@alum.mit.edu</email>
</author>
<published>2015-07-03T13:59:32Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=6c8afe495b2cb6e2069942d7c006f6660e186690'/>
<id>urn:sha1:6c8afe495b2cb6e2069942d7c006f6660e186690</id>
<content type='text'>
It is currently declared to return int, which could overflow for
large files.

Signed-off-by: Michael Haggerty &lt;mhagger@alum.mit.edu&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>strbuf_getwholeline: use getdelim if it is available</title>
<updated>2015-04-16T15:15:05Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-04-16T09:01:38Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0cc30e0e842a25846e76e09f62a1d425a25ee556'/>
<id>urn:sha1:0cc30e0e842a25846e76e09f62a1d425a25ee556</id>
<content type='text'>
We spend a lot of time in strbuf_getwholeline in a tight
loop reading characters from a stdio handle into a buffer.
The libc getdelim() function can do this for us with less
overhead. It's in POSIX.1-2008, and was a GNU extension
before that. Therefore we can't rely on it, but can fall
back to the existing getc loop when it is not available.

The HAVE_GETDELIM knob is turned on automatically for Linux,
where we have glibc. We don't need to set any new
feature-test macros, because we already define _GNU_SOURCE.
Other systems that implement getdelim may need to other
macros (probably _POSIX_C_SOURCE &gt;= 200809L), but we can
address that along with setting the Makefile knob after
testing the feature on those systems.

Running "git rev-parse refs/heads/does-not-exist" on a repo
with an extremely large (1.6GB) packed-refs file went from
(best-of-5):

  real    0m8.601s
  user    0m8.084s
  sys     0m0.524s

to:

  real    0m6.768s
  user    0m6.340s
  sys     0m0.432s

for a wall-clock speedup of 21%.

Based on a patch from Rasmus Villemoes &lt;rv@rasmusvillemoes.dk&gt;.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>strbuf_getwholeline: avoid calling strbuf_grow</title>
<updated>2015-04-16T15:15:05Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-04-16T08:58:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=f80c153bea4e0ea86f5b6d32e77df0b69501ee18'/>
<id>urn:sha1:f80c153bea4e0ea86f5b6d32e77df0b69501ee18</id>
<content type='text'>
As with the recent speedup to strbuf_addch, we can avoid
calling strbuf_grow() in a tight loop of single-character
adds by instead checking strbuf_avail.

Note that we would instead call strbuf_addch directly here,
but it does more work than necessary: it will NUL-terminate
the result for each character read. Instead, in this loop we
read the characters one by one and then add the terminator
manually at the end.

Running "git rev-parse refs/heads/does-not-exist" on a repo
with an extremely large (1.6GB) packed-refs file went from
(best-of-5):

  real    0m10.948s
  user    0m10.548s
  sys     0m0.412s

to:

  real    0m8.601s
  user    0m8.084s
  sys     0m0.524s

for a wall-clock speedup of 21%.

Helped-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>strbuf_getwholeline: use getc_unlocked</title>
<updated>2015-04-16T15:15:04Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-04-16T08:49:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=82912d1de86ae3d7f247bc3b16a81afd01aa31c7'/>
<id>urn:sha1:82912d1de86ae3d7f247bc3b16a81afd01aa31c7</id>
<content type='text'>
strbuf_getwholeline calls getc in a tight loop. On modern
libc implementations, the stdio code locks the handle for
every operation, which means we are paying a significant
overhead.  We can get around this by locking the handle for
the whole loop and using the unlocked variant.

Running "git rev-parse refs/heads/does-not-exist" on a repo
with an extremely large (1.6GB) packed-refs file went from:

  real    0m18.900s
  user    0m18.472s
  sys     0m0.448s

to:

  real    0m10.953s
  user    0m10.384s
  sys     0m0.580s

for a wall-clock speedup of 42%. All times are best-of-3,
and done on a glibc 2.19 system.

Note that we call into strbuf_grow while holding the lock.
It's possible for that function to call other stdio
functions (e.g., printing to stderr when dying due to malloc
error); however, the POSIX.1-2001 definition of flockfile
makes it clear that the locks are per-handle, so we are fine
unless somebody else tries to read from our same handle.
This doesn't ever happen in the current code, and is
unlikely to be added in the future (we would have to do
something exotic like add a die_routine that tried to read
from stdin).

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>strbuf_getwholeline: use getc macro</title>
<updated>2015-04-16T15:15:04Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-04-16T08:48:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3446a59b3950d57960e27f8a2c7e41462bd2bcf4'/>
<id>urn:sha1:3446a59b3950d57960e27f8a2c7e41462bd2bcf4</id>
<content type='text'>
strbuf_getwholeline calls fgetc in a tight loop. Using the
getc form, which can be implemented as a macro, should be
faster (and we do not care about it evaluating our argument
twice, as we just have a plain variable).

On my glibc system, running "git rev-parse
refs/heads/does-not-exist" on a file with an extremely large
(1.6GB) packed-refs file went from (best of 3 runs):

  real    0m19.383s
  user    0m18.876s
  sys     0m0.528s

to:

  real    0m18.900s
  user    0m18.472s
  sys     0m0.448s

for a wall-clock speedup of 2.5%.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jc/strbuf-add-lines-avoid-sp-ht-sequence'</title>
<updated>2015-01-07T20:49:19Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-01-07T20:49:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=58e0362eddba1678a71c8990862053ff989527b6'/>
<id>urn:sha1:58e0362eddba1678a71c8990862053ff989527b6</id>
<content type='text'>
The commented output used to blindly add a SP before the payload
line, resulting in "# \t&lt;indented text&gt;\n" when the payload began
with a HT.  Instead, produce "#\t&lt;indented text&gt;\n".

* jc/strbuf-add-lines-avoid-sp-ht-sequence:
  strbuf_add_commented_lines(): avoid SP-HT sequence in commented lines
</content>
</entry>
<entry>
<title>strbuf_add_commented_lines(): avoid SP-HT sequence in commented lines</title>
<updated>2014-10-27T21:13:59Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2014-10-27T21:13:15Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d55aeb7687448189327ad058096b55431da5ea42'/>
<id>urn:sha1:d55aeb7687448189327ad058096b55431da5ea42</id>
<content type='text'>
The strbuf_add_commented_lines() function passes a pair of prefixes,
one to be used for a non-empty line, and the other for an empty
line, to underlying add_lines().  The former is set to a comment
char followed by a SP, while the latter is set to just the comment
char.  This is designed to give a SP after the comment character,
e.g. "# &lt;user text&gt;\n", on a line with some text, and to avoid
emitting an unsightly "# \n" for an empty line.

Teach this machinery to also use the latter space-less prefix when
the payload line begins with a tab, to show e.g. "#\t&lt;user text&gt;\n";
otherwise we will end up showing "# \t&lt;user text&gt;\n" which is
similarly unsightly.

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
