All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Jeremiah Mahler <jmmahler@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH v2 01/19] add strbuf_set operations
Date: Thu, 12 Jun 2014 12:21:48 +0200	[thread overview]
Message-ID: <53997F3C.9010608@alum.mit.edu> (raw)
In-Reply-To: <20140612071045.GC25353@hudson.localdomain>

On 06/12/2014 09:10 AM, Jeremiah Mahler wrote:
> On Wed, Jun 11, 2014 at 02:05:35PM +0200, Michael Haggerty wrote:
>> [...]
>> If there were a function like strbuf_grow_to(sb, len):
>>
>> void strbuf_grow_to(struct strbuf *sb, size_t len)
>> {
>> 	int new_buf = !sb->alloc;
>> 	if (unsigned_add_overflows(len, 1))
>> 		die("you want to use way too much memory");
>> 	if (new_buf)
>> 		sb->buf = NULL;
>> 	ALLOC_GROW(sb->buf, len + 1, sb->alloc);
>> 	if (new_buf)
>> 		sb->buf[0] = '\0';
>> }
>>
> grow_to() which could reduce in size, interesting.

I don't understand what you mean by "could reduce in size".  This
function can only grow, never reduce, the size of the strbuf, because
ALLOC_GROW doesn't do anything unless the requested size is larger than
the currently-allocated size.

>> (strbuf_grow() could call it:
>>
>> static inline void strbuf_grow(struct strbuf *sb, size_t extra)
>> {
>> 	if (unsigned_add_overflows(sb->len, extra))
>> 		die("you want to use way too much memory");
>> 	strbuf_grow_to(sb, sb->len + extra);
>> }
>>
>> ), then your function could be minimized to
>>
>> void strbuf_set(struct strbuf *sb, const void *data, size_t len)
>> {
>> 	strbuf_grow_to(sb, len);
>> 	memcpy(sb->buf, data, len);
>> 	strbuf_setlen(sb, len);
>> }
>>
>> I think strbuf_grow_to() would be useful in other situations too.
>>
>> This is just an idea; I'm not saying that you have to make this change.
>>
> I like your idea.  I am leaning towards doing the un-optimized
> strbuf_set operations first, then optimizing in a later patch.

That's a good plan.

In case you're interested, I sketched what the strbuf_grow_to() changes
might look like, and also looked for other places in the code where
strbuf_grow_to() could be used instead of strbuf_grow() [1].  This is
only a sketch; I haven't even tested the result.  Feel free to use what
you want from it.

Michael

[1] Branch "strbuf-grow-to-sketch" on https://github.com/mhagger/git

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

  reply	other threads:[~2014-06-12 10:21 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-09 22:19 [PATCH v2 00/19] add strbuf_set operations Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 01/19] " Jeremiah Mahler
2014-06-11  8:42   ` Eric Sunshine
2014-06-12  7:10     ` Jeremiah Mahler
2014-06-11 12:05   ` Michael Haggerty
2014-06-12  7:10     ` Jeremiah Mahler
2014-06-12 10:21       ` Michael Haggerty [this message]
2014-06-12 23:59         ` Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 02/19] sha1_name: simplify via strbuf_set() Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 03/19] fast-import: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 04/19] builtin/remote: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 05/19] branch: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 06/19] builtin/branch: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 07/19] builtin/checkout: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 08/19] builtin/mailinfo: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 09/19] builtin/tag: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 10/19] date: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 11/19] diffcore-order: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 12/19] http-backend: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 13/19] http: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 14/19] ident: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 15/19] remote-curl: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 16/19] submodule: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 17/19] transport: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 18/19] vcs-svn/svndump: " Jeremiah Mahler
2014-06-09 22:19 ` [PATCH v2 19/19] wt-status: " Jeremiah Mahler
2014-06-11  8:09 ` [PATCH v2 00/19] add strbuf_set operations Eric Sunshine
2014-06-12  7:09   ` Jeremiah Mahler

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=53997F3C.9010608@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=git@vger.kernel.org \
    --cc=jmmahler@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.