aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/iface.go
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-02-17 15:14:21 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2021-02-23 06:01:29 +0000
commite52149822b54811cedaaa87013de3fa4bc634e95 (patch)
tree34bdc306bf2c00c662add4a459ea5dcff0e4d670 /src/runtime/iface.go
parent86deb459de6a309503aa445a7d686bd139354e5e (diff)
downloadgo-e52149822b54811cedaaa87013de3fa4bc634e95.tar.gz
go-e52149822b54811cedaaa87013de3fa4bc634e95.zip
cmd/compile: simplify assert{E,I}2I{,2} calling conventions
This CL rebases CL 273694 on top of master with @mdempsky's permission. For assertE2I and assertI2I, there's no need to pass through the interface's data pointer: it's always going to come back unmodified. For assertE2I2 and assertI2I2, there's no need for an extra bool result parameter: it's redundant with testing the returned interface value for nil. Change-Id: Ic92d4409ad381952f875d3d74b8cf11c32702fa6 Reviewed-on: https://go-review.googlesource.com/c/go/+/292892 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/runtime/iface.go')
-rw-r--r--src/runtime/iface.go28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/runtime/iface.go b/src/runtime/iface.go
index 0504b89363..02b18dabff 100644
--- a/src/runtime/iface.go
+++ b/src/runtime/iface.go
@@ -447,23 +447,18 @@ func convI2I(inter *interfacetype, i iface) (r iface) {
return
}
-func assertI2I(inter *interfacetype, i iface) (r iface) {
- tab := i.tab
+func assertI2I(inter *interfacetype, tab *itab) *itab {
if tab == nil {
// explicit conversions require non-nil interface value.
panic(&TypeAssertionError{nil, nil, &inter.typ, ""})
}
if tab.inter == inter {
- r.tab = tab
- r.data = i.data
- return
+ return tab
}
- r.tab = getitab(inter, tab._type, false)
- r.data = i.data
- return
+ return getitab(inter, tab._type, false)
}
-func assertI2I2(inter *interfacetype, i iface) (r iface, b bool) {
+func assertI2I2(inter *interfacetype, i iface) (r iface) {
tab := i.tab
if tab == nil {
return
@@ -476,22 +471,18 @@ func assertI2I2(inter *interfacetype, i iface) (r iface, b bool) {
}
r.tab = tab
r.data = i.data
- b = true
return
}
-func assertE2I(inter *interfacetype, e eface) (r iface) {
- t := e._type
+func assertE2I(inter *interfacetype, t *_type) *itab {
if t == nil {
// explicit conversions require non-nil interface value.
panic(&TypeAssertionError{nil, nil, &inter.typ, ""})
}
- r.tab = getitab(inter, t, false)
- r.data = e.data
- return
+ return getitab(inter, t, false)
}
-func assertE2I2(inter *interfacetype, e eface) (r iface, b bool) {
+func assertE2I2(inter *interfacetype, e eface) (r iface) {
t := e._type
if t == nil {
return
@@ -502,18 +493,17 @@ func assertE2I2(inter *interfacetype, e eface) (r iface, b bool) {
}
r.tab = tab
r.data = e.data
- b = true
return
}
//go:linkname reflect_ifaceE2I reflect.ifaceE2I
func reflect_ifaceE2I(inter *interfacetype, e eface, dst *iface) {
- *dst = assertE2I(inter, e)
+ *dst = iface{assertE2I(inter, e._type), e.data}
}
//go:linkname reflectlite_ifaceE2I internal/reflectlite.ifaceE2I
func reflectlite_ifaceE2I(inter *interfacetype, e eface, dst *iface) {
- *dst = assertE2I(inter, e)
+ *dst = iface{assertE2I(inter, e._type), e.data}
}
func iterate_itabs(fn func(*itab)) {