Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-04-18 02:12:50 +0400
committerRussell Belfer <rb@github.com>2012-04-25 21:42:37 +0400
commit19fa2bc111d50dc2bafb1393b87b5ba119615ae2 (patch)
tree103a62cf49834958b18562f411abd18b2a438ce6 /src/attr.c
parent2bc8fa0227d549006a9870620ca1f2e08a0c305e (diff)
Convert attrs and diffs to use string pools
This converts the git attr related code (including ignores) and the git diff related code (and implicitly the status code) to use `git_pools` for storing strings. This reduces the number of small blocks allocated dramatically.
Diffstat (limited to 'src/attr.c')
-rw-r--r--src/attr.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/attr.c b/src/attr.c
index c02289363..f5d50bb42 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -167,6 +167,7 @@ int git_attr_add_macro(
{
int error;
git_attr_rule *macro = NULL;
+ git_pool *pool;
if (git_attr_cache__init(repo) < 0)
return -1;
@@ -174,13 +175,15 @@ int git_attr_add_macro(
macro = git__calloc(1, sizeof(git_attr_rule));
GITERR_CHECK_ALLOC(macro);
- macro->match.pattern = git__strdup(name);
+ pool = &git_repository_attr_cache(repo)->pool;
+
+ macro->match.pattern = git_pool_strdup(pool, name);
GITERR_CHECK_ALLOC(macro->match.pattern);
macro->match.length = strlen(macro->match.pattern);
macro->match.flags = GIT_ATTR_FNMATCH_MACRO;
- error = git_attr_assignment__parse(repo, &macro->assigns, &values);
+ error = git_attr_assignment__parse(repo, pool, &macro->assigns, &values);
if (!error)
error = git_attr_cache__insert_macro(repo, macro);
@@ -221,7 +224,7 @@ int git_attr_cache__lookup_or_create_file(
return 0;
}
- if (git_attr_file__new(&file) < 0)
+ if (git_attr_file__new(&file, &cache->pool) < 0)
return -1;
if (loader)
@@ -384,6 +387,10 @@ int git_attr_cache__init(git_repository *repo)
return -1;
}
+ /* allocate string pool */
+ if (git_pool_init(&cache->pool, 1, 0) < 0)
+ return -1;
+
cache->initialized = 1;
/* insert default macros */
@@ -393,30 +400,33 @@ int git_attr_cache__init(git_repository *repo)
void git_attr_cache_flush(
git_repository *repo)
{
- git_hashtable *table;
+ git_attr_cache *cache;
if (!repo)
return;
- if ((table = git_repository_attr_cache(repo)->files) != NULL) {
- git_attr_file *file;
-
- GIT_HASHTABLE_FOREACH_VALUE(table, file, git_attr_file__free(file));
- git_hashtable_free(table);
+ cache = git_repository_attr_cache(repo);
- git_repository_attr_cache(repo)->files = NULL;
+ if (cache->files != NULL) {
+ git_attr_file *file;
+ GIT_HASHTABLE_FOREACH_VALUE(
+ cache->files, file, git_attr_file__free(file));
+ git_hashtable_free(cache->files);
+ cache->files = NULL;
}
- if ((table = git_repository_attr_cache(repo)->macros) != NULL) {
+ if (cache->macros != NULL) {
git_attr_rule *rule;
- GIT_HASHTABLE_FOREACH_VALUE(table, rule, git_attr_rule__free(rule));
- git_hashtable_free(table);
-
- git_repository_attr_cache(repo)->macros = NULL;
+ GIT_HASHTABLE_FOREACH_VALUE(
+ cache->macros, rule, git_attr_rule__free(rule));
+ git_hashtable_free(cache->macros);
+ cache->macros = NULL;
}
- git_repository_attr_cache(repo)->initialized = 0;
+ git_pool_clear(&cache->pool);
+
+ cache->initialized = 0;
}
int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro)