Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Unified Diff: src/pkg/reflect/value.go

Issue 3608041: code review 3608041: reflect: add ArrayType.Slice, ArrayValue.Slice (Closed)
Patch Set: code review 3608041: Right now it's not possible to use the data within a Created 14 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/reflect/type.go ('k') | src/pkg/runtime/type.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/reflect/value.go
===================================================================
--- a/src/pkg/reflect/value.go
+++ b/src/pkg/reflect/value.go
@@ -397,6 +397,7 @@
Len() int
Cap() int
Elem(i int) Value
+ Slice(beg, end int) *SliceValue
addr() addr
}
@@ -456,6 +457,20 @@
return newValue(typ, p, v.canSet)
}
+// Slice returns a slice of the array v.
+func (v *ArrayValue) Slice(beg, end int) *SliceValue {
+ cap := v.Cap()
+ if beg < 0 || end < beg || end > cap {
+ panic("slice index out of bounds")
+ }
+ typ := v.typ.(*ArrayType).Slice()
+ s := new(SliceHeader)
+ s.Data = uintptr(v.addr()) + uintptr(beg)*typ.Elem().Size()
+ s.Len = end - beg
+ s.Cap = cap - beg
+ return newValue(typ, addr(s), v.canSet).(*SliceValue)
+}
+
/*
* slice
*/
« no previous file with comments | « src/pkg/reflect/type.go ('k') | src/pkg/runtime/type.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b