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
53571f2f
Commit
53571f2f
authored
Nov 21, 2015
by
Edward Thomson
Committed by
Edward Thomson
May 26, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vector: more sensible names for `grow_at`/`shrink_at`
parent
440e3bae
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
26 deletions
+26
-26
src/apply.c
+2
-2
src/vector.c
+10
-10
src/vector.h
+2
-2
tests/core/vector.c
+12
-12
No files found.
src/apply.c
View file @
53571f2f
...
...
@@ -137,10 +137,10 @@ static int update_hunk(
int
error
=
0
;
if
(
postlen
>
prelen
)
error
=
git_vector_
grow_at
(
error
=
git_vector_
insert_null
(
&
image
->
lines
,
linenum
,
(
postlen
-
prelen
));
else
if
(
prelen
>
postlen
)
error
=
git_vector_
shrink_at
(
error
=
git_vector_
remove_range
(
&
image
->
lines
,
linenum
,
(
prelen
-
postlen
));
if
(
error
)
{
...
...
src/vector.c
View file @
53571f2f
...
...
@@ -331,33 +331,33 @@ int git_vector_resize_to(git_vector *v, size_t new_length)
return
0
;
}
int
git_vector_
grow_at
(
git_vector
*
v
,
size_t
idx
,
size_t
grow
_len
)
int
git_vector_
insert_null
(
git_vector
*
v
,
size_t
idx
,
size_t
insert
_len
)
{
size_t
new_length
;
assert
(
grow
_len
>
0
&&
idx
<=
v
->
length
);
assert
(
insert
_len
>
0
&&
idx
<=
v
->
length
);
GITERR_CHECK_ALLOC_ADD
(
&
new_length
,
v
->
length
,
grow
_len
);
GITERR_CHECK_ALLOC_ADD
(
&
new_length
,
v
->
length
,
insert
_len
);
if
(
new_length
>
v
->
_alloc_size
&&
resize_vector
(
v
,
new_length
)
<
0
)
return
-
1
;
memmove
(
&
v
->
contents
[
idx
+
grow
_len
],
&
v
->
contents
[
idx
],
memmove
(
&
v
->
contents
[
idx
+
insert
_len
],
&
v
->
contents
[
idx
],
sizeof
(
void
*
)
*
(
v
->
length
-
idx
));
memset
(
&
v
->
contents
[
idx
],
0
,
sizeof
(
void
*
)
*
grow
_len
);
memset
(
&
v
->
contents
[
idx
],
0
,
sizeof
(
void
*
)
*
insert
_len
);
v
->
length
=
new_length
;
return
0
;
}
int
git_vector_
shrink_at
(
git_vector
*
v
,
size_t
idx
,
size_t
shrink
_len
)
int
git_vector_
remove_range
(
git_vector
*
v
,
size_t
idx
,
size_t
remove
_len
)
{
size_t
new_length
=
v
->
length
-
shrink
_len
;
size_t
new_length
=
v
->
length
-
remove
_len
;
size_t
end_idx
=
0
;
assert
(
shrink
_len
>
0
);
assert
(
remove
_len
>
0
);
if
(
git__add_sizet_overflow
(
&
end_idx
,
idx
,
shrink
_len
))
if
(
git__add_sizet_overflow
(
&
end_idx
,
idx
,
remove
_len
))
assert
(
0
);
assert
(
end_idx
<=
v
->
length
);
...
...
@@ -366,7 +366,7 @@ int git_vector_shrink_at(git_vector *v, size_t idx, size_t shrink_len)
memmove
(
&
v
->
contents
[
idx
],
&
v
->
contents
[
end_idx
],
sizeof
(
void
*
)
*
(
v
->
length
-
end_idx
));
memset
(
&
v
->
contents
[
new_length
],
0
,
sizeof
(
void
*
)
*
shrink
_len
);
memset
(
&
v
->
contents
[
new_length
],
0
,
sizeof
(
void
*
)
*
remove
_len
);
v
->
length
=
new_length
;
return
0
;
...
...
src/vector.h
View file @
53571f2f
...
...
@@ -93,8 +93,8 @@ void git_vector_remove_matching(
void
*
payload
);
int
git_vector_resize_to
(
git_vector
*
v
,
size_t
new_length
);
int
git_vector_
grow_at
(
git_vector
*
v
,
size_t
idx
,
size_t
grow
_len
);
int
git_vector_
shrink_at
(
git_vector
*
v
,
size_t
idx
,
size_t
shrink
_len
);
int
git_vector_
insert_null
(
git_vector
*
v
,
size_t
idx
,
size_t
insert
_len
);
int
git_vector_
remove_range
(
git_vector
*
v
,
size_t
idx
,
size_t
remove
_len
);
int
git_vector_set
(
void
**
old
,
git_vector
*
v
,
size_t
position
,
void
*
value
);
...
...
tests/core/vector.c
View file @
53571f2f
...
...
@@ -338,40 +338,40 @@ void test_core_vector__grow_and_shrink(void)
git_vector_insert
(
&
x
,
(
void
*
)
0x09
);
git_vector_insert
(
&
x
,
(
void
*
)
0x0a
);
git_vector_
shrink_at
(
&
x
,
0
,
1
);
git_vector_
remove_range
(
&
x
,
0
,
1
);
assert_vector
(
&
x
,
expected1
,
ARRAY_SIZE
(
expected1
));
git_vector_
shrink_at
(
&
x
,
1
,
1
);
git_vector_
remove_range
(
&
x
,
1
,
1
);
assert_vector
(
&
x
,
expected2
,
ARRAY_SIZE
(
expected2
));
git_vector_
shrink_at
(
&
x
,
4
,
3
);
git_vector_
remove_range
(
&
x
,
4
,
3
);
assert_vector
(
&
x
,
expected3
,
ARRAY_SIZE
(
expected3
));
git_vector_
shrink_at
(
&
x
,
3
,
2
);
git_vector_
remove_range
(
&
x
,
3
,
2
);
assert_vector
(
&
x
,
expected4
,
ARRAY_SIZE
(
expected4
));
git_vector_
grow_at
(
&
x
,
0
,
2
);
git_vector_
insert_null
(
&
x
,
0
,
2
);
assert_vector
(
&
x
,
expected5
,
ARRAY_SIZE
(
expected5
));
git_vector_
grow_at
(
&
x
,
5
,
1
);
git_vector_
insert_null
(
&
x
,
5
,
1
);
assert_vector
(
&
x
,
expected6
,
ARRAY_SIZE
(
expected6
));
git_vector_
grow_at
(
&
x
,
4
,
3
);
git_vector_
insert_null
(
&
x
,
4
,
3
);
assert_vector
(
&
x
,
expected7
,
ARRAY_SIZE
(
expected7
));
git_vector_
shrink_at
(
&
x
,
0
,
3
);
git_vector_
remove_range
(
&
x
,
0
,
3
);
assert_vector
(
&
x
,
expected8
,
ARRAY_SIZE
(
expected8
));
git_vector_
shrink_at
(
&
x
,
1
,
2
);
git_vector_
remove_range
(
&
x
,
1
,
2
);
assert_vector
(
&
x
,
expected9
,
ARRAY_SIZE
(
expected9
));
git_vector_
shrink_at
(
&
x
,
2
,
2
);
git_vector_
remove_range
(
&
x
,
2
,
2
);
assert_vector
(
&
x
,
expectedA
,
ARRAY_SIZE
(
expectedA
));
git_vector_
shrink_at
(
&
x
,
1
,
1
);
git_vector_
remove_range
(
&
x
,
1
,
1
);
assert_vector
(
&
x
,
expectedB
,
ARRAY_SIZE
(
expectedB
));
git_vector_
shrink_at
(
&
x
,
0
,
1
);
git_vector_
remove_range
(
&
x
,
0
,
1
);
assert_vector
(
&
x
,
NULL
,
0
);
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