|
37 | 37 | #include "unpack-trees.h"
|
38 | 38 | #include "xdiff-interface.h"
|
39 | 39 |
|
| 40 | +#define USE_MEMORY_POOL 1 /* faster, but obscures memory leak hunting */ |
| 41 | + |
40 | 42 | /*
|
41 | 43 | * We have many arrays of size 3. Whenever we have such an array, the
|
42 | 44 | * indices refer to one of the sides of the three-way merge. This is so
|
@@ -339,6 +341,17 @@ struct merge_options_internal {
|
339 | 341 | */
|
340 | 342 | struct strmap conflicted;
|
341 | 343 |
|
| 344 | + /* |
| 345 | + * pool: memory pool for fast allocation/deallocation |
| 346 | + * |
| 347 | + * We allocate room for lots of filenames and auxiliary data |
| 348 | + * structures in merge_options_internal, and it tends to all be |
| 349 | + * freed together too. Using a memory pool for these provides a |
| 350 | + * nice speedup. |
| 351 | + */ |
| 352 | + struct mem_pool internal_pool; |
| 353 | + struct mem_pool *pool; /* NULL, or pointer to internal_pool */ |
| 354 | + |
342 | 355 | /*
|
343 | 356 | * paths_to_free: additional list of strings to free
|
344 | 357 | *
|
@@ -603,6 +616,12 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
|
603 | 616 | strmap_clear(&opti->output, 0);
|
604 | 617 | }
|
605 | 618 |
|
| 619 | +#if USE_MEMORY_POOL |
| 620 | + mem_pool_discard(&opti->internal_pool, 0); |
| 621 | + if (!reinitialize) |
| 622 | + opti->pool = NULL; |
| 623 | +#endif |
| 624 | + |
606 | 625 | /* Clean out callback_data as well. */
|
607 | 626 | FREE_AND_NULL(renames->callback_data);
|
608 | 627 | renames->callback_data_nr = renames->callback_data_alloc = 0;
|
@@ -4381,6 +4400,12 @@ static void merge_start(struct merge_options *opt, struct merge_result *result)
|
4381 | 4400 |
|
4382 | 4401 | /* Initialization of various renames fields */
|
4383 | 4402 | renames = &opt->priv->renames;
|
| 4403 | +#if USE_MEMORY_POOL |
| 4404 | + mem_pool_init(&opt->priv->internal_pool, 0); |
| 4405 | + opt->priv->pool = &opt->priv->internal_pool; |
| 4406 | +#else |
| 4407 | + opt->priv->pool = NULL; |
| 4408 | +#endif |
4384 | 4409 | for (i = MERGE_SIDE1; i <= MERGE_SIDE2; i++) {
|
4385 | 4410 | strintmap_init_with_options(&renames->dirs_removed[i],
|
4386 | 4411 | NOT_RELEVANT, NULL, 0);
|
|
0 commit comments