cache API: add a "INDEX_STATE_INIT" macro/function, add release_index()
Hopefully in some not so distant future, we'll get advantages from always initializing the "repo" member of the "struct index_state". To make that easier let's introduce an initialization macro & function. The various ad-hoc initialization of the structure can then be changed over to it, and we can remove the various "0" assignments in discard_index() in favor of calling index_state_init() at the end. While not strictly necessary, let's also change the CALLOC_ARRAY() of various "struct index_state *" to use an ALLOC_ARRAY() followed by index_state_init() instead. We're then adding the release_index() function and converting some callers (including some of these allocations) over to it if they either won't need to use their "struct index_state" again, or are just about to call index_state_init(). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Acked-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5bdf6d4ac0
commit
2f6b1eb794
13
cache.h
13
cache.h
@ -360,6 +360,19 @@ struct index_state {
|
||||
struct pattern_list *sparse_checkout_patterns;
|
||||
};
|
||||
|
||||
/**
|
||||
* A "struct index_state istate" must be initialized with
|
||||
* INDEX_STATE_INIT or the corresponding index_state_init().
|
||||
*
|
||||
* If the variable won't be used again, use release_index() to free()
|
||||
* its resources. If it needs to be used again use discard_index(),
|
||||
* which does the same thing, but will use use index_state_init() at
|
||||
* the end.
|
||||
*/
|
||||
#define INDEX_STATE_INIT { 0 }
|
||||
void index_state_init(struct index_state *istate);
|
||||
void release_index(struct index_state *istate);
|
||||
|
||||
/* Name hashing */
|
||||
int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
|
||||
void add_name_hash(struct index_state *istate, struct cache_entry *ce);
|
||||
|
Reference in New Issue
Block a user