From: Jeff King <peff@peff.net> To: Jonathan Nieder <jrnieder@gmail.com> Cc: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>, "Jakub Narebski" <jnareb@gmail.com>, "Ted Ts\'o" <tytso@mit.edu>, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>, "Clemens Buchacher" <drizzd@aon.at>, "Shawn O. Pearce" <spearce@spearce.org>, "David Barr" <davidbarr@google.com> Subject: [PATCH 2/3] fast-export: use object to uint32 map instead of "decorate" Date: Thu, 14 Jul 2011 13:52:11 -0400 Message-ID: <20110714175211.GB21771@sigill.intra.peff.net> (raw) In-Reply-To: <20110714173454.GA21657@sigill.intra.peff.net> Previously we encoded the "mark" mapping inside the "void *" field of a "struct decorate". It's a little more natural for us to do so using a data structure made for holding actual values. Signed-off-by: Jeff King <peff@peff.net> --- And this is an example of use. It doesn't save all that much code, but I think it's a little more natural. It can also save some bytes of the hash value in each entry if your pointers are larger than 32-bit. builtin/fast-export.c | 36 +++++++++++------------------------- map.c | 2 ++ map.h | 2 ++ 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index daf1945..fd50503 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -12,7 +12,7 @@ #include "diffcore.h" #include "log-tree.h" #include "revision.h" -#include "decorate.h" +#include "map.h" #include "string-list.h" #include "utf8.h" #include "parse-options.h" @@ -59,7 +59,7 @@ static int parse_opt_tag_of_filtered_mode(const struct option *opt, return 0; } -static struct decoration idnums; +static struct map_object_uint32 idnums; static uint32_t last_idnum; static int has_unshown_parent(struct commit *commit) @@ -73,20 +73,9 @@ static int has_unshown_parent(struct commit *commit) return 0; } -/* Since intptr_t is C99, we do not use it here */ -static inline uint32_t *mark_to_ptr(uint32_t mark) -{ - return ((uint32_t *)NULL) + mark; -} - -static inline uint32_t ptr_to_mark(void * mark) -{ - return (uint32_t *)mark - (uint32_t *)NULL; -} - static inline void mark_object(struct object *object, uint32_t mark) { - add_decoration(&idnums, object, mark_to_ptr(mark)); + map_set_object_uint32(&idnums, object, mark, NULL); } static inline void mark_next_object(struct object *object) @@ -96,10 +85,9 @@ static inline void mark_next_object(struct object *object) static int get_object_mark(struct object *object) { - void *decoration = lookup_decoration(&idnums, object); - if (!decoration) - return 0; - return ptr_to_mark(decoration); + uint32_t ret = 0; + map_get_object_uint32(&idnums, object, &ret); + return ret; } static void show_progress(void) @@ -537,8 +525,7 @@ static void handle_tags_and_duplicates(struct string_list *extra_refs) static void export_marks(char *file) { unsigned int i; - uint32_t mark; - struct object_decoration *deco = idnums.hash; + struct map_entry_object_uint32 *map = idnums.hash; FILE *f; int e = 0; @@ -547,15 +534,14 @@ static void export_marks(char *file) die_errno("Unable to open marks file %s for writing.", file); for (i = 0; i < idnums.size; i++) { - if (deco->base && deco->base->type == 1) { - mark = ptr_to_mark(deco->decoration); - if (fprintf(f, ":%"PRIu32" %s\n", mark, - sha1_to_hex(deco->base->sha1)) < 0) { + if (map->used && map->key->type == 1) { + if (fprintf(f, ":%"PRIu32" %s\n", map->value, + sha1_to_hex(map->key->sha1)) < 0) { e = 1; break; } } - deco++; + map++; } e |= ferror(f); diff --git a/map.c b/map.c index 378cecb..28f885e 100644 --- a/map.c +++ b/map.c @@ -84,3 +84,5 @@ int map_get_##name(struct map_##name *m, \ } \ return 0; \ } + +MAP_IMPLEMENT(object_uint32, struct object *, uint32_t, cmp_obj, hash_obj) diff --git a/map.h b/map.h index 496c5d1..e80d85d 100644 --- a/map.h +++ b/map.h @@ -21,4 +21,6 @@ extern int map_set_##name(struct map_##name *, \ vtype value, \ vtype *old); \ +DECLARE_MAP(object_uint32, struct object *, uint32_t) + #endif /* MAP_H */ -- 1.7.6.38.ge5b33
next prev parent reply index Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-07-13 6:47 [RFC/PATCHv2 0/6] generation numbers for faster traversals Jeff King 2011-07-13 6:57 ` [RFC/PATCHv2 1/6] decorate: allow storing values instead of pointers Jeff King 2011-07-13 17:52 ` Jonathan Nieder 2011-07-13 20:08 ` Jeff King 2011-07-14 17:34 ` Jeff King 2011-07-14 17:51 ` [PATCH 1/3] implement generic key/value map Jeff King 2011-07-14 18:52 ` Bert Wesarg 2011-07-14 18:54 ` Bert Wesarg 2011-07-14 18:55 ` Jeff King 2011-07-14 19:07 ` Bert Wesarg 2011-07-14 19:14 ` Jeff King 2011-07-14 19:18 ` Bert Wesarg 2011-07-14 17:52 ` Jeff King [this message] 2011-07-15 9:40 ` [PATCH 2/3] fast-export: use object to uint32 map instead of "decorate" Sverre Rabbelier 2011-07-15 20:00 ` Jeff King 2011-07-14 17:53 ` [PATCH 3/3] decorate: use "map" for the underlying implementation Jeff King 2011-07-14 21:06 ` [RFC/PATCHv2 1/6] decorate: allow storing values instead of pointers Junio C Hamano 2011-08-04 22:43 ` [RFC/PATCH 0/5] macro-based key/value maps Jeff King 2011-08-04 22:45 ` [PATCH 1/5] implement generic key/value map Jeff King 2011-08-04 22:46 ` [PATCH 2/5] fast-export: use object to uint32 map instead of "decorate" Jeff King 2011-08-04 22:46 ` [PATCH 3/5] decorate: use "map" for the underlying implementation Jeff King 2011-08-04 22:46 ` [PATCH 4/5] map: implement persistent maps Jeff King 2011-08-04 22:46 ` [PATCH 5/5] implement metadata cache subsystem Jeff King 2011-08-05 11:03 ` [RFC/PATCH 0/5] macro-based key/value maps Jeff King 2011-08-05 15:31 ` René Scharfe 2011-08-06 6:30 ` Jeff King 2011-07-13 7:04 ` [RFC/PATCHv2 2/6] add metadata-cache infrastructure Jeff King 2011-07-13 8:18 ` Bert Wesarg 2011-07-13 8:31 ` Jeff King 2011-07-13 8:45 ` Bert Wesarg 2011-07-13 19:18 ` Jeff King 2011-07-13 19:40 ` Junio C Hamano 2011-07-13 19:33 ` Junio C Hamano 2011-07-13 20:25 ` Jeff King 2011-07-13 7:05 ` [RFC/PATCHv2 3/6] commit: add commit_generation function Jeff King 2011-07-13 14:26 ` Eric Sunshine 2011-07-13 7:05 ` [RFC/PATCHv2 4/6] pretty: support %G to show the generation number of a commit Jeff King 2011-07-13 7:06 ` [RFC/PATCHv2 5/6] check commit generation cache validity against grafts Jeff King 2011-07-13 14:26 ` Eric Sunshine 2011-07-13 19:35 ` Jeff King 2011-07-13 7:06 ` [RFC/PATCHv2 6/6] limit "contains" traversals based on commit generation Jeff King 2011-07-13 7:23 ` Jeff King 2011-07-13 20:33 ` Junio C Hamano 2011-07-13 20:58 ` Jeff King 2011-07-13 21:12 ` Junio C Hamano 2011-07-13 21:18 ` Jeff King 2011-07-15 18:22 ` Junio C Hamano 2011-07-15 20:40 ` Jeff King 2011-07-15 21:04 ` Junio C Hamano 2011-07-15 21:14 ` Jeff King 2011-07-15 21:01 ` Generation numbers and replacement objects Jakub Narebski 2011-07-15 21:10 ` Jeff King 2011-07-16 21:10 ` Jakub Narebski 2011-08-04 22:48 [RFC/PATCH 0/2] patch-id caching Jeff King 2011-08-04 22:49 ` [PATCH 1/2] cherry: read default config Jeff King 2011-08-04 22:49 ` [PATCH 2/2] cache patch ids on disk Jeff King 2011-08-04 22:52 ` Jeff King
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20110714175211.GB21771@sigill.intra.peff.net \ --to=peff@peff.net \ --cc=avarab@gmail.com \ --cc=davidbarr@google.com \ --cc=drizzd@aon.at \ --cc=git@vger.kernel.org \ --cc=gitster@pobox.com \ --cc=jnareb@gmail.com \ --cc=jrnieder@gmail.com \ --cc=spearce@spearce.org \ --cc=tytso@mit.edu \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Mailing List Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/git/0 git/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 git git/ https://lore.kernel.org/git \ git@vger.kernel.org public-inbox-index git Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.kernel.vger.git AGPL code for this site: git clone https://public-inbox.org/public-inbox.git