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
29e6eb21
Commit
29e6eb21
authored
Jul 02, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make a description of the slice header public
R=rsc DELTA=18 (3 added, 0 deleted, 15 changed) OCL=31086 CL=31094
parent
c7a9d981
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
15 deletions
+18
-15
src/pkg/reflect/value.go
src/pkg/reflect/value.go
+18
-15
No files found.
src/pkg/reflect/value.go
View file @
29e6eb21
...
@@ -563,17 +563,20 @@ func copyArray(dst ArrayValue, src ArrayValue, n int);
...
@@ -563,17 +563,20 @@ func copyArray(dst ArrayValue, src ArrayValue, n int);
uint32 cap;
uint32 cap;
};
};
*/
*/
type
runtimeSlice
struct
{
data
Addr
;
// A published version of the Slice header so that clients don't have a separate copy of the definition.
len
uint32
;
// SliceHeader is not useful to clients unless they use unsafe.Pointer.
cap
uint32
;
type
SliceHeader
struct
{
Data
uintptr
;
Len
uint32
;
Cap
uint32
;
}
}
type
sliceValueStruct
struct
{
type
sliceValueStruct
struct
{
commonValue
;
commonValue
;
elemtype
Type
;
elemtype
Type
;
elemsize
int
;
elemsize
int
;
slice
*
runtimeSlice
;
slice
*
SliceHeader
;
}
}
func
(
v
*
sliceValueStruct
)
IsSlice
()
bool
{
func
(
v
*
sliceValueStruct
)
IsSlice
()
bool
{
...
@@ -581,18 +584,18 @@ func (v *sliceValueStruct) IsSlice() bool {
...
@@ -581,18 +584,18 @@ func (v *sliceValueStruct) IsSlice() bool {
}
}
func
(
v
*
sliceValueStruct
)
Len
()
int
{
func
(
v
*
sliceValueStruct
)
Len
()
int
{
return
int
(
v
.
slice
.
l
en
);
return
int
(
v
.
slice
.
L
en
);
}
}
func
(
v
*
sliceValueStruct
)
Cap
()
int
{
func
(
v
*
sliceValueStruct
)
Cap
()
int
{
return
int
(
v
.
slice
.
c
ap
);
return
int
(
v
.
slice
.
C
ap
);
}
}
func
(
v
*
sliceValueStruct
)
SetLen
(
len
int
)
{
func
(
v
*
sliceValueStruct
)
SetLen
(
len
int
)
{
if
len
>
v
.
Cap
()
{
if
len
>
v
.
Cap
()
{
panicln
(
"reflect: sliceValueStruct.SetLen"
,
len
,
v
.
Cap
());
panicln
(
"reflect: sliceValueStruct.SetLen"
,
len
,
v
.
Cap
());
}
}
v
.
slice
.
l
en
=
uint32
(
len
);
v
.
slice
.
L
en
=
uint32
(
len
);
}
}
func
(
v
*
sliceValueStruct
)
Set
(
src
ArrayValue
)
{
func
(
v
*
sliceValueStruct
)
Set
(
src
ArrayValue
)
{
...
@@ -607,7 +610,7 @@ func (v *sliceValueStruct) Set(src ArrayValue) {
...
@@ -607,7 +610,7 @@ func (v *sliceValueStruct) Set(src ArrayValue) {
}
}
func
(
v
*
sliceValueStruct
)
Elem
(
i
int
)
Value
{
func
(
v
*
sliceValueStruct
)
Elem
(
i
int
)
Value
{
data_uint
:=
uintptr
(
v
.
slice
.
data
)
+
uintptr
(
i
*
v
.
elemsize
);
data_uint
:=
v
.
slice
.
Data
+
uintptr
(
i
*
v
.
elemsize
);
return
newValueAddr
(
v
.
elemtype
,
Addr
(
data_uint
));
return
newValueAddr
(
v
.
elemtype
,
Addr
(
data_uint
));
}
}
...
@@ -616,7 +619,7 @@ func (v *sliceValueStruct) CopyFrom(src ArrayValue, n int) {
...
@@ -616,7 +619,7 @@ func (v *sliceValueStruct) CopyFrom(src ArrayValue, n int) {
}
}
func
(
v
*
sliceValueStruct
)
IsNil
()
bool
{
func
(
v
*
sliceValueStruct
)
IsNil
()
bool
{
return
uintptr
(
v
.
slice
.
data
)
==
0
return
v
.
slice
.
Data
==
0
}
}
type
arrayValueStruct
struct
{
type
arrayValueStruct
struct
{
...
@@ -668,7 +671,7 @@ func arrayCreator(typ Type, addr Addr) Value {
...
@@ -668,7 +671,7 @@ func arrayCreator(typ Type, addr Addr) Value {
v
.
typ
=
typ
;
v
.
typ
=
typ
;
v
.
elemtype
=
arraytype
.
Elem
();
v
.
elemtype
=
arraytype
.
Elem
();
v
.
elemsize
=
v
.
elemtype
.
Size
();
v
.
elemsize
=
v
.
elemtype
.
Size
();
v
.
slice
=
(
*
runtimeSlice
)(
addr
);
v
.
slice
=
(
*
SliceHeader
)(
addr
);
return
v
;
return
v
;
}
}
v
:=
new
(
arrayValueStruct
);
v
:=
new
(
arrayValueStruct
);
...
@@ -897,15 +900,15 @@ func NewSliceValue(typ ArrayType, len, cap int) ArrayValue {
...
@@ -897,15 +900,15 @@ func NewSliceValue(typ ArrayType, len, cap int) ArrayValue {
return
nil
return
nil
}
}
array
:=
new
(
runtimeSlice
);
array
:=
new
(
SliceHeader
);
size
:=
typ
.
Elem
()
.
Size
()
*
cap
;
size
:=
typ
.
Elem
()
.
Size
()
*
cap
;
if
size
==
0
{
if
size
==
0
{
size
=
1
;
size
=
1
;
}
}
data
:=
make
([]
uint8
,
size
);
data
:=
make
([]
uint8
,
size
);
array
.
data
=
Addr
(
&
data
[
0
]
);
array
.
Data
=
uintptr
(
Addr
(
&
data
[
0
])
);
array
.
l
en
=
uint32
(
len
);
array
.
L
en
=
uint32
(
len
);
array
.
c
ap
=
uint32
(
cap
);
array
.
C
ap
=
uint32
(
cap
);
return
newValueAddr
(
typ
,
Addr
(
array
))
.
(
ArrayValue
);
return
newValueAddr
(
typ
,
Addr
(
array
))
.
(
ArrayValue
);
}
}
...
...
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