Thread (16 messages) flat view 16 messages, 6 authors, 2016-06-15

Re: [PATCH] Rework strbuf API and semantics.

From: Pierre Habouzit <hidden>
Date: 2016-06-15 22:43:33

Possibly related (same subject, not in this thread)

On Tue, Sep 04, 2007 at 03:44:30PM +0000, Johannes Schindelin wrote:
Hi,

On Tue, 4 Sep 2007, Pierre Habouzit wrote:
quoted
+void strbuf_grow(struct strbuf *sb, size_t extra) {
+	if (sb->len + extra + STRBUF_GROW_STEP < sb->len)
+		die("you want to use way to much memory");
+
+	sb->alloc = ((sb->len + extra) + STRBUF_GROW_STEP) & ~(STRBUF_GROW_STEP - 1);
+	sb->buf   = xrealloc(sb->buf, sb->alloc);
+}
Why not use ALLOC_GROW()?  Seems to me more efficient than growing by 1kB 
blocks all the time, for big strings as for short strings.
  ooooh, now I'm guilty of not knowing all git APIs very well yet :) Indeed,
this should just be:

    void strbuf_grow(struct strbuf *sb, size_t extra) {
        if (sb->len + extra + 1 < sb->len)
            die("you want to use way to much memory");
        ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc);
    }

  This is definitely better on so many levels !

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help