~mdw
/
tig
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Cache all queries for refs based on ID
[tig]
/
tig.c
diff --git
a/tig.c
b/tig.c
index
be165b9
..
faf9193
100644
(file)
--- a/
tig.c
+++ b/
tig.c
@@
-2197,39
+2197,57
@@
init_display(void)
static struct ref *refs;
static size_t refs_size;
static struct ref *refs;
static size_t refs_size;
+/* Id <-> ref store */
+static struct ref ***id_refs;
+static size_t id_refs_size;
+
static struct ref **
get_refs(char *id)
{
static struct ref **
get_refs(char *id)
{
- struct ref **id_refs = NULL;
- size_t id_refs_size = 0;
+ struct ref ***tmp_id_refs;
+ struct ref **ref_list = NULL;
+ size_t ref_list_size = 0;
size_t i;
size_t i;
+ for (i = 0; i < id_refs_size; i++)
+ if (!strcmp(id, id_refs[i][0]->id))
+ return id_refs[i];
+
+ tmp_id_refs = realloc(id_refs, (id_refs_size + 1) * sizeof(*id_refs));
+ if (!tmp_id_refs)
+ return NULL;
+
+ id_refs = tmp_id_refs;
+
for (i = 0; i < refs_size; i++) {
struct ref **tmp;
if (strcmp(id, refs[i].id))
continue;
for (i = 0; i < refs_size; i++) {
struct ref **tmp;
if (strcmp(id, refs[i].id))
continue;
- tmp = realloc(
id_refs, (id_refs_size + 1) * sizeof(*id_refs
));
+ tmp = realloc(
ref_list, (ref_list_size + 1) * sizeof(*ref_list
));
if (!tmp) {
if (!tmp) {
- if (
id_refs
)
- free(
id_refs
);
+ if (
ref_list
)
+ free(
ref_list
);
return NULL;
}
return NULL;
}
-
id_refs
= tmp;
- if (
id_refs
_size > 0)
-
id_refs[id_refs
_size - 1]->next = 1;
-
id_refs[id_refs
_size] = &refs[i];
+
ref_list
= tmp;
+ if (
ref_list
_size > 0)
+
ref_list[ref_list
_size - 1]->next = 1;
+
ref_list[ref_list
_size] = &refs[i];
/* XXX: The properties of the commit chains ensures that we can
* safely modify the shared ref. The repo references will
* always be similar for the same id. */
/* XXX: The properties of the commit chains ensures that we can
* safely modify the shared ref. The repo references will
* always be similar for the same id. */
-
id_refs[id_refs
_size]->next = 0;
-
id_refs
_size++;
+
ref_list[ref_list
_size]->next = 0;
+
ref_list
_size++;
}
}
- return id_refs;
+ if (ref_list)
+ id_refs[id_refs_size++] = ref_list;
+
+ return ref_list;
}
static int
}
static int