diff options
| author | Vicent Martà <tanoku@gmail.com> | 2011-07-06 10:55:06 -0700 |
|---|---|---|
| committer | Vicent Martà <tanoku@gmail.com> | 2011-07-06 10:55:06 -0700 |
| commit | bf9a2e98b83c8de2b8664a91167b5529ae1d9d39 (patch) | |
| tree | 6db283bad395273d08b96f779ff349d00530f948 /src/vector.c | |
| parent | c68dee2a74fc6c5a2adab12857e9840254647a4b (diff) | |
| parent | 245adf4f3cc1d47352e626ef53372d07761d84cf (diff) | |
| download | libgit2-bf9a2e98b83c8de2b8664a91167b5529ae1d9d39.tar.gz | |
Merge pull request #296 from kiryl/index-optimization
Index optimization
Diffstat (limited to 'src/vector.c')
| -rw-r--r-- | src/vector.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/vector.c b/src/vector.c index 0451eb082..2fc051f0c 100644 --- a/src/vector.c +++ b/src/vector.c @@ -94,7 +94,7 @@ void git_vector_sort(git_vector *v) if (v->sorted || v->_cmp == NULL) return; - qsort(v->contents, v->length, sizeof(void *), v->_cmp); + git__msort(v->contents, v->length, sizeof(void *), v->_cmp); v->sorted = 1; } @@ -162,6 +162,26 @@ int git_vector_remove(git_vector *v, unsigned int idx) return GIT_SUCCESS; } +void git_vector_uniq(git_vector *v) +{ + git_vector_cmp cmp; + unsigned int i, j; + + if (v->length <= 1) + return; + + git_vector_sort(v); + cmp = v->_cmp ? v->_cmp : strict_comparison; + + for (i = 0, j = 1 ; j < v->length; ++j) + if (!cmp(v->contents + i, v->contents + j)) + v->contents[i] = v->contents[j]; + else + v->contents[++i] = v->contents[j]; + + v->length -= j - i - 1; +} + void git_vector_clear(git_vector *v) { assert(v); |
