Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
191adce8
Commit
191adce8
authored
Aug 27, 2013
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vector: Teach git_vector_uniq() to free while deduplicating
parent
c9ffa84b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
6 deletions
+12
-6
src/util.h
+4
-1
src/vector.c
+6
-3
src/vector.h
+1
-1
tests-clar/core/vector.c
+1
-1
No files found.
src/util.h
View file @
191adce8
...
@@ -82,7 +82,10 @@ GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
...
@@ -82,7 +82,10 @@ GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
return
new_ptr
;
return
new_ptr
;
}
}
#define git__free(ptr) free(ptr)
GIT_INLINE
(
void
)
git__free
(
void
*
ptr
)
{
free
(
ptr
);
}
#define STRCMP_CASESELECT(IGNORE_CASE, STR1, STR2) \
#define STRCMP_CASESELECT(IGNORE_CASE, STR1, STR2) \
((IGNORE_CASE) ? strcasecmp((STR1), (STR2)) : strcmp((STR1), (STR2)))
((IGNORE_CASE) ? strcasecmp((STR1), (STR2)) : strcmp((STR1), (STR2)))
...
...
src/vector.c
View file @
191adce8
...
@@ -220,7 +220,7 @@ void git_vector_pop(git_vector *v)
...
@@ -220,7 +220,7 @@ void git_vector_pop(git_vector *v)
v
->
length
--
;
v
->
length
--
;
}
}
void
git_vector_uniq
(
git_vector
*
v
)
void
git_vector_uniq
(
git_vector
*
v
,
void
(
*
git_free_cb
)(
void
*
)
)
{
{
git_vector_cmp
cmp
;
git_vector_cmp
cmp
;
size_t
i
,
j
;
size_t
i
,
j
;
...
@@ -232,9 +232,12 @@ void git_vector_uniq(git_vector *v)
...
@@ -232,9 +232,12 @@ void git_vector_uniq(git_vector *v)
cmp
=
v
->
_cmp
?
v
->
_cmp
:
strict_comparison
;
cmp
=
v
->
_cmp
?
v
->
_cmp
:
strict_comparison
;
for
(
i
=
0
,
j
=
1
;
j
<
v
->
length
;
++
j
)
for
(
i
=
0
,
j
=
1
;
j
<
v
->
length
;
++
j
)
if
(
!
cmp
(
v
->
contents
[
i
],
v
->
contents
[
j
]))
if
(
!
cmp
(
v
->
contents
[
i
],
v
->
contents
[
j
]))
{
if
(
git_free_cb
)
git_free_cb
(
v
->
contents
[
i
]);
v
->
contents
[
i
]
=
v
->
contents
[
j
];
v
->
contents
[
i
]
=
v
->
contents
[
j
];
else
}
else
v
->
contents
[
++
i
]
=
v
->
contents
[
j
];
v
->
contents
[
++
i
]
=
v
->
contents
[
j
];
v
->
length
-=
j
-
i
-
1
;
v
->
length
-=
j
-
i
-
1
;
...
...
src/vector.h
View file @
191adce8
...
@@ -71,7 +71,7 @@ int git_vector_insert_sorted(git_vector *v, void *element,
...
@@ -71,7 +71,7 @@ int git_vector_insert_sorted(git_vector *v, void *element,
int
(
*
on_dup
)(
void
**
old
,
void
*
new
));
int
(
*
on_dup
)(
void
**
old
,
void
*
new
));
int
git_vector_remove
(
git_vector
*
v
,
size_t
idx
);
int
git_vector_remove
(
git_vector
*
v
,
size_t
idx
);
void
git_vector_pop
(
git_vector
*
v
);
void
git_vector_pop
(
git_vector
*
v
);
void
git_vector_uniq
(
git_vector
*
v
);
void
git_vector_uniq
(
git_vector
*
v
,
void
(
*
git_free_cb
)(
void
*
)
);
void
git_vector_remove_matching
(
void
git_vector_remove_matching
(
git_vector
*
v
,
int
(
*
match
)(
const
git_vector
*
v
,
size_t
idx
));
git_vector
*
v
,
int
(
*
match
)(
const
git_vector
*
v
,
size_t
idx
));
...
...
tests-clar/core/vector.c
View file @
191adce8
...
@@ -54,7 +54,7 @@ void test_core_vector__2(void)
...
@@ -54,7 +54,7 @@ void test_core_vector__2(void)
cl_git_pass
(
git_vector_insert
(
&
x
,
ptrs
[
1
]));
cl_git_pass
(
git_vector_insert
(
&
x
,
ptrs
[
1
]));
cl_assert
(
x
.
length
==
5
);
cl_assert
(
x
.
length
==
5
);
git_vector_uniq
(
&
x
);
git_vector_uniq
(
&
x
,
NULL
);
cl_assert
(
x
.
length
==
2
);
cl_assert
(
x
.
length
==
2
);
git_vector_free
(
&
x
);
git_vector_free
(
&
x
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment