Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
3dc278d3
Commit
3dc278d3
authored
Dec 12, 2011
by
Gustavo Niemeyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reflect: fix Slice cap
R=golang-dev, dsymonds, r, rsc CC=golang-dev
https://golang.org/cl/5483044
parent
e6f5a90b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
6 deletions
+18
-6
src/pkg/reflect/all_test.go
src/pkg/reflect/all_test.go
+17
-5
src/pkg/reflect/value.go
src/pkg/reflect/value.go
+1
-1
No files found.
src/pkg/reflect/all_test.go
View file @
3dc278d3
...
...
@@ -1557,14 +1557,26 @@ func TestSmallNegativeInt(t *testing.T) {
func
TestSlice
(
t
*
testing
.
T
)
{
xs
:=
[]
int
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
}
v
:=
ValueOf
(
xs
)
.
Slice
(
3
,
5
)
.
Interface
()
.
([]
int
)
if
len
(
v
)
!=
2
||
v
[
0
]
!=
4
||
v
[
1
]
!=
5
{
t
.
Errorf
(
"xs.Slice(3, 5) = %v"
,
v
)
if
len
(
v
)
!=
2
{
t
.
Errorf
(
"len(xs.Slice(3, 5)) = %d"
,
len
(
v
))
}
if
cap
(
v
)
!=
5
{
t
.
Errorf
(
"cap(xs.Slice(3, 5)) = %d"
,
cap
(
v
))
}
if
!
DeepEqual
(
v
[
0
:
5
],
xs
[
3
:
])
{
t
.
Errorf
(
"xs.Slice(3, 5)[0:5] = %v"
,
v
[
0
:
5
])
}
xa
:=
[
7
]
int
{
10
,
20
,
30
,
40
,
50
,
60
,
7
0
}
xa
:=
[
8
]
int
{
10
,
20
,
30
,
40
,
50
,
60
,
70
,
8
0
}
v
=
ValueOf
(
&
xa
)
.
Elem
()
.
Slice
(
2
,
5
)
.
Interface
()
.
([]
int
)
if
len
(
v
)
!=
3
||
v
[
0
]
!=
30
||
v
[
1
]
!=
40
||
v
[
2
]
!=
50
{
t
.
Errorf
(
"xa.Slice(2, 5) = %v"
,
v
)
if
len
(
v
)
!=
3
{
t
.
Errorf
(
"len(xa.Slice(2, 5)) = %d"
,
len
(
v
))
}
if
cap
(
v
)
!=
6
{
t
.
Errorf
(
"cap(xa.Slice(2, 5)) = %d"
,
cap
(
v
))
}
if
!
DeepEqual
(
v
[
0
:
6
],
xa
[
2
:
])
{
t
.
Errorf
(
"xs.Slice(2, 5)[0:6] = %v"
,
v
[
0
:
6
])
}
}
...
...
src/pkg/reflect/value.go
View file @
3dc278d3
...
...
@@ -1356,7 +1356,7 @@ func (v Value) Slice(beg, end int) Value {
s
:=
(
*
SliceHeader
)(
unsafe
.
Pointer
(
&
x
))
s
.
Data
=
uintptr
(
base
)
+
uintptr
(
beg
)
*
toCommonType
(
typ
.
elem
)
.
Size
()
s
.
Len
=
end
-
beg
s
.
Cap
=
end
-
beg
s
.
Cap
=
cap
-
beg
fl
:=
v
.
flag
&
flagRO
|
flagIndir
|
flag
(
Slice
)
<<
flagKindShift
return
Value
{
typ
.
common
(),
unsafe
.
Pointer
(
&
x
),
fl
}
...
...
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