summaryrefslogtreecommitdiff
path: root/decorate.c
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2017-12-08 00:14:24 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-12-08 17:16:27 (GMT)
commitddd3e3124276133d0c7e902287ab4113f660f6d7 (patch)
treee4e7b903528eb62e81a9f8660a40aa3ddb3ff14c /decorate.c
parent95ec6b1b3393eb6e26da40c565520a8db9796e9f (diff)
downloadgit-ddd3e3124276133d0c7e902287ab4113f660f6d7.zip
git-ddd3e3124276133d0c7e902287ab4113f660f6d7.tar.gz
git-ddd3e3124276133d0c7e902287ab4113f660f6d7.tar.bz2
decorate: clean up and document API
Improve the names of the identifiers in decorate.h, document them, and add an example of how to use these functions. The example is compiled and run as part of the test suite. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'decorate.c')
-rw-r--r--decorate.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/decorate.c b/decorate.c
index 270eb25..de31331 100644
--- a/decorate.c
+++ b/decorate.c
@@ -14,20 +14,20 @@ static unsigned int hash_obj(const struct object *obj, unsigned int n)
static void *insert_decoration(struct decoration *n, const struct object *base, void *decoration)
{
int size = n->size;
- struct object_decoration *hash = n->hash;
+ struct decoration_entry *entries = n->entries;
unsigned int j = hash_obj(base, size);
- while (hash[j].base) {
- if (hash[j].base == base) {
- void *old = hash[j].decoration;
- hash[j].decoration = decoration;
+ while (entries[j].base) {
+ if (entries[j].base == base) {
+ void *old = entries[j].decoration;
+ entries[j].decoration = decoration;
return old;
}
if (++j >= size)
j = 0;
}
- hash[j].base = base;
- hash[j].decoration = decoration;
+ entries[j].base = base;
+ entries[j].decoration = decoration;
n->nr++;
return NULL;
}
@@ -36,24 +36,23 @@ static void grow_decoration(struct decoration *n)
{
int i;
int old_size = n->size;
- struct object_decoration *old_hash = n->hash;
+ struct decoration_entry *old_entries = n->entries;
n->size = (old_size + 1000) * 3 / 2;
- n->hash = xcalloc(n->size, sizeof(struct object_decoration));
+ n->entries = xcalloc(n->size, sizeof(struct decoration_entry));
n->nr = 0;
for (i = 0; i < old_size; i++) {
- const struct object *base = old_hash[i].base;
- void *decoration = old_hash[i].decoration;
+ const struct object *base = old_entries[i].base;
+ void *decoration = old_entries[i].decoration;
if (!decoration)
continue;
insert_decoration(n, base, decoration);
}
- free(old_hash);
+ free(old_entries);
}
-/* Add a decoration pointer, return any old one */
void *add_decoration(struct decoration *n, const struct object *obj,
void *decoration)
{
@@ -64,7 +63,6 @@ void *add_decoration(struct decoration *n, const struct object *obj,
return insert_decoration(n, obj, decoration);
}
-/* Lookup a decoration pointer */
void *lookup_decoration(struct decoration *n, const struct object *obj)
{
unsigned int j;
@@ -74,7 +72,7 @@ void *lookup_decoration(struct decoration *n, const struct object *obj)
return NULL;
j = hash_obj(obj, n->size);
for (;;) {
- struct object_decoration *ref = n->hash + j;
+ struct decoration_entry *ref = n->entries + j;
if (ref->base == obj)
return ref->decoration;
if (!ref->base)