summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e2eb469)
raw | patch | inline | side by side (parent: e2eb469)
author | Shawn O. Pearce <spearce@spearce.org> | |
Mon, 28 Aug 2006 17:15:48 +0000 (13:15 -0400) | ||
committer | Shawn O. Pearce <spearce@spearce.org> | |
Sun, 14 Jan 2007 07:15:10 +0000 (02:15 -0500) |
Since most commits and tag objects are around the same size and we
only generate one at a time we can reuse the same buffer rather than
xmalloc'ing and free'ing the buffer every time we generate a commit.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
only generate one at a time we can reuse the same buffer rather than
xmalloc'ing and free'ing the buffer every time we generate a commit.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
fast-import.c | patch | blob | history |
diff --git a/fast-import.c b/fast-import.c
index 8d15a057393f81041b734d18dbbc0a7c9357cf0d..3d991020057c549d7cfbdcb917853ced07c44582 100644 (file)
--- a/fast-import.c
+++ b/fast-import.c
/* Input stream parsing */
static struct strbuf command_buf;
static unsigned long next_mark;
+static struct dbuf new_data;
static FILE* branch_log;
return r;
}
+static void size_dbuf(struct dbuf *b, size_t maxlen)
+{
+ if (b->buffer) {
+ if (b->capacity >= maxlen)
+ return;
+ free(b->buffer);
+ }
+ b->capacity = ((maxlen / 1024) + 1) * 1024;
+ b->buffer = xmalloc(b->capacity);
+}
+
static void insert_mark(unsigned long idnum, struct object_entry *oe)
{
struct mark_set *s = marks;
maxlen += t->entries[i]->name->str_len + 34;
}
- if (b->buffer) {
- if (b->capacity < maxlen)
- b->capacity = ((maxlen / 1024) + 1) * 1024;
- b->buffer = xrealloc(b->buffer, b->capacity);
- } else {
- b->capacity = ((maxlen / 1024) + 1) * 1024;
- b->buffer = xmalloc(b->capacity);
- }
-
+ size_dbuf(b, maxlen);
c = b->buffer;
for (i = 0; i < t->entry_count; i++) {
struct tree_entry *e = t->entries[i];
char *sp;
char *author = NULL;
char *committer = NULL;
- char *body;
/* Obtain the branch name from the rest of our command */
sp = strchr(command_buf.buf, ' ') + 1;
/* build the tree and the commit */
store_tree(&b->branch_tree);
- body = xmalloc(97 + msglen
+ size_dbuf(&new_data, 97 + msglen
+ (author
? strlen(author) + strlen(committer)
: 2 * strlen(committer)));
- sp = body;
+ sp = new_data.buffer;
sp += sprintf(sp, "tree %s\n",
sha1_to_hex(b->branch_tree.versions[1].sha1));
if (!is_null_sha1(b->sha1))
free(committer);
free(msg);
- store_object(OBJ_COMMIT, body, sp - body, NULL, b->sha1, next_mark);
- free(body);
+ store_object(OBJ_COMMIT,
+ new_data.buffer, sp - (char*)new_data.buffer,
+ NULL, b->sha1, next_mark);
b->last_commit = object_count_by_type[OBJ_COMMIT];
if (branch_log) {
struct branch *s;
void *msg;
size_t msglen;
- char *body;
struct tag *t;
unsigned long from_mark = 0;
unsigned char sha1[20];
msg = cmd_data(&msglen);
/* build the tag object */
- body = xmalloc(67 + strlen(t->name) + strlen(tagger) + msglen);
- sp = body;
+ size_dbuf(&new_data, 67+strlen(t->name)+strlen(tagger)+msglen);
+ sp = new_data.buffer;
sp += sprintf(sp, "object %s\n", sha1_to_hex(sha1));
sp += sprintf(sp, "type %s\n", type_names[OBJ_COMMIT]);
sp += sprintf(sp, "tag %s\n", t->name);
free(tagger);
free(msg);
- store_object(OBJ_TAG, body, sp - body, NULL, t->sha1, 0);
- free(body);
+ store_object(OBJ_TAG, new_data.buffer, sp - (char*)new_data.buffer,
+ NULL, t->sha1, 0);
if (branch_log) {
int need_dq = quote_c_style(t->name, NULL, NULL, 0);
{
const char *base_name;
int i;
- unsigned long est_obj_cnt = 1000;
+ unsigned long est_obj_cnt = object_entry_alloc;
char *pack_name;
char *idx_name;
struct stat sb;