summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b2ff9a4)
raw | patch | inline | side by side (parent: b2ff9a4)
author | Jonas Fonseca <fonseca@diku.dk> | |
Wed, 18 Feb 2009 10:56:31 +0000 (11:56 +0100) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Wed, 18 Feb 2009 10:59:32 +0000 (11:59 +0100) |
tig.c | patch | blob | history |
index 566f8031d01047e92f9359e42690108f7f9d5486..16b0df20aba44d1cb208d2937807810d96446617 100644 (file)
--- a/tig.c
+++ b/tig.c
#define DEFINE_ALLOCATOR(name, type, chunk_size) \
static type * \
-name(type **mem, size_t *alloc, size_t new_size) \
+name(type **mem, size_t size, size_t increase) \
{ \
- size_t num_chunks = *alloc / chunk_size; \
- size_t num_chunks_new = (new_size + chunk_size - 1) / chunk_size; \
+ size_t num_chunks = (size + chunk_size - 1) / chunk_size; \
+ size_t num_chunks_new = (size + increase + chunk_size - 1) / chunk_size;\
type *tmp = *mem; \
\
if (mem == NULL || num_chunks != num_chunks_new) { \
- size_t memsize = num_chunks_new * chunk_size; \
- tmp = realloc(tmp, memsize * sizeof(type)); \
+ tmp = realloc(tmp, num_chunks_new * chunk_size * sizeof(type)); \
if (tmp) \
- *mem = tmp, *alloc = memsize; \
+ *mem = tmp; \
} \
\
return tmp; \
/* Buffering */
size_t lines; /* Total number of lines */
struct line *line; /* Line index */
- size_t line_alloc; /* Total number of allocated lines */
unsigned int digits; /* Number of digits in the lines member. */
/* Drawing */
view->yoffset = 0;
view->lines = 0;
view->lineno = 0;
- view->line_alloc = 0;
view->vid[0] = 0;
view->update_secs = 0;
}
{
struct line *line;
- if (!realloc_lines(&view->line, &view->line_alloc, view->lines + 1))
+ if (!realloc_lines(&view->line, view->lines, 1))
return NULL;
line = &view->line[view->lines++];
get_author(const char *name)
{
static const char **authors;
- static size_t authors_alloc;
static size_t authors_size;
int from = 0, to = authors_size - 1;
from = pos + 1;
}
- if (!realloc_authors(&authors, &authors_alloc, authors_size + 1))
+ if (!realloc_authors(&authors, authors_size, 1))
return NULL;
name = strdup(name);
if (!name)
int i;
if (!stage_chunks) {
- static size_t alloc = 0;
-
for (line = view->line; line < view->line + view->lines; line++) {
if (line->type != LINE_DIFF_CHUNK)
continue;
- if (!realloc_ints(&stage_chunk, &alloc, stage_chunks + 1)) {
+ if (!realloc_ints(&stage_chunk, stage_chunks, 1)) {
report("Allocation failure");
return;
}
*/
static struct ref *refs = NULL;
-static size_t refs_alloc = 0;
static size_t refs_size = 0;
/* Id <-> ref store */
static struct ref ***id_refs = NULL;
-static size_t id_refs_alloc = 0;
static size_t id_refs_size = 0;
DEFINE_ALLOCATOR(realloc_refs, struct ref, 256)
get_refs(const char *id)
{
struct ref **ref_list = NULL;
- size_t ref_list_alloc = 0;
size_t ref_list_size = 0;
size_t i;
if (!strcmp(id, id_refs[i][0]->id))
return id_refs[i];
- if (!realloc_refs_lists(&id_refs, &id_refs_alloc, id_refs_size + 1))
+ if (!realloc_refs_lists(&id_refs, id_refs_size, 1))
return NULL;
for (i = 0; i < refs_size; i++) {
if (strcmp(id, refs[i].id))
continue;
- if (!realloc_refs_list(&ref_list, &ref_list_alloc, ref_list_size + 1))
+ if (!realloc_refs_list(&ref_list, ref_list_size, 1))
return ref_list;
ref_list[ref_list_size] = &refs[i];
return OK;
}
- if (!realloc_refs(&refs, &refs_alloc, refs_size + 1))
+ if (!realloc_refs(&refs, refs_size, 1))
return ERR;
ref = &refs[refs_size++];