Skip to content

Commit 0d9398d

Browse files
Reduced to v1.19 only
1 parent f18194a commit 0d9398d

File tree

6 files changed

+51
-157
lines changed

6 files changed

+51
-157
lines changed

compiler/natives/src/internal/reflectlite/reflectlite.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func reflectType(typ *js.Object) *rtype {
5050
rt := &rtype{
5151
size: uintptr(typ.Get("size").Int()),
5252
kind: uint8(typ.Get("kind").Int()),
53-
str: newNameOff(newNameWithoutEmbed(internalStr(typ.Get("string")), "", typ.Get("exported").Bool())),
53+
str: newNameOff(newName(internalStr(typ.Get("string")), "", typ.Get("exported").Bool(), false)),
5454
}
5555
js.InternalObject(rt).Set(idJsType, typ)
5656
typ.Set(idReflectType, js.InternalObject(rt))
@@ -69,7 +69,7 @@ func reflectType(typ *js.Object) *rtype {
6969
continue
7070
}
7171
reflectMethods = append(reflectMethods, method{
72-
name: newNameOff(newNameWithoutEmbed(internalStr(m.Get("name")), "", exported)),
72+
name: newNameOff(newName(internalStr(m.Get("name")), "", exported, false)),
7373
mtyp: newTypeOff(reflectType(m.Get("typ"))),
7474
})
7575
}
@@ -81,12 +81,12 @@ func reflectType(typ *js.Object) *rtype {
8181
continue
8282
}
8383
reflectMethods = append(reflectMethods, method{
84-
name: newNameOff(newNameWithoutEmbed(internalStr(m.Get("name")), "", exported)),
84+
name: newNameOff(newName(internalStr(m.Get("name")), "", exported, false)),
8585
mtyp: newTypeOff(reflectType(m.Get("typ"))),
8686
})
8787
}
8888
ut := &uncommonType{
89-
pkgPath: newNameOff(newNameWithoutEmbed(internalStr(typ.Get("pkg")), "", false)),
89+
pkgPath: newNameOff(newName(internalStr(typ.Get("pkg")), "", false, false)),
9090
mcount: uint16(methodSet.Length()),
9191
xcount: xcount,
9292
_methods: reflectMethods,
@@ -141,13 +141,13 @@ func reflectType(typ *js.Object) *rtype {
141141
for i := range imethods {
142142
m := methods.Index(i)
143143
imethods[i] = imethod{
144-
name: newNameOff(newNameWithoutEmbed(internalStr(m.Get("name")), "", internalStr(m.Get("pkg")) == "")),
144+
name: newNameOff(newName(internalStr(m.Get("name")), "", internalStr(m.Get("pkg")) == "", false)),
145145
typ: newTypeOff(reflectType(m.Get("typ"))),
146146
}
147147
}
148148
setKindType(rt, &interfaceType{
149149
rtype: *rt,
150-
pkgPath: newNameWithoutEmbed(internalStr(typ.Get("pkg")), "", false),
150+
pkgPath: newName(internalStr(typ.Get("pkg")), "", false, false),
151151
methods: imethods,
152152
})
153153
case Map:
@@ -167,11 +167,16 @@ func reflectType(typ *js.Object) *rtype {
167167
fields := typ.Get("fields")
168168
reflectFields := make([]structField, fields.Length())
169169
for i := range reflectFields {
170-
reflectFields[i] = buildStructField(i, fields.Index(i))
170+
f := fields.Index(i)
171+
reflectFields[i] = structField{
172+
name: newName(internalStr(f.Get("name")), internalStr(f.Get("tag")), f.Get("exported").Bool(), f.Get("embedded").Bool()),
173+
typ: reflectType(f.Get("typ")),
174+
offset: uintptr(i),
175+
}
171176
}
172177
setKindType(rt, &structType{
173178
rtype: *rt,
174-
pkgPath: newNameWithoutEmbed(internalStr(typ.Get("pkgPath")), "", false),
179+
pkgPath: newName(internalStr(typ.Get("pkgPath")), "", false, false),
175180
fields: reflectFields,
176181
})
177182
}
@@ -242,6 +247,20 @@ func (n name) name() (s string) { return nameMap[n.bytes].name }
242247
func (n name) tag() (s string) { return nameMap[n.bytes].tag }
243248
func (n name) pkgPath() string { return "" }
244249
func (n name) isExported() bool { return nameMap[n.bytes].exported }
250+
func (n name) embedded() bool { return nameMap[n.bytes].embedded }
251+
252+
func newName(n, tag string, exported, embedded bool) name {
253+
b := new(byte)
254+
nameMap[b] = &nameData{
255+
name: n,
256+
tag: tag,
257+
exported: exported,
258+
embedded: embedded,
259+
}
260+
return name{
261+
bytes: b,
262+
}
263+
}
245264

246265
var nameOffList []name
247266

compiler/natives/src/internal/reflectlite/reflectlite1.18.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

compiler/natives/src/internal/reflectlite/relfectlite1.19.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

compiler/natives/src/reflect/reflect.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func reflectType(typ *js.Object) *rtype {
6363
rt := &rtype{
6464
size: uintptr(typ.Get("size").Int()),
6565
kind: uint8(typ.Get("kind").Int()),
66-
str: resolveReflectName(newNameWithoutEmbed(internalStr(typ.Get("string")), "", typ.Get("exported").Bool())),
66+
str: resolveReflectName(newName(internalStr(typ.Get("string")), "", typ.Get("exported").Bool(), false)),
6767
}
6868
js.InternalObject(rt).Set("jsType", typ)
6969
typ.Set("reflectType", js.InternalObject(rt))
@@ -99,7 +99,7 @@ func reflectType(typ *js.Object) *rtype {
9999
})
100100
}
101101
ut := &uncommonType{
102-
pkgPath: resolveReflectName(newNameWithoutEmbed(internalStr(typ.Get("pkg")), "", false)),
102+
pkgPath: resolveReflectName(newName(internalStr(typ.Get("pkg")), "", false, false)),
103103
mcount: uint16(methodSet.Length()),
104104
xcount: xcount,
105105
_methods: reflectMethods,
@@ -160,7 +160,7 @@ func reflectType(typ *js.Object) *rtype {
160160
}
161161
setKindType(rt, &interfaceType{
162162
rtype: *rt,
163-
pkgPath: newNameWithoutEmbed(internalStr(typ.Get("pkg")), "", false),
163+
pkgPath: newName(internalStr(typ.Get("pkg")), "", false, false),
164164
methods: imethods,
165165
})
166166
case Map:
@@ -180,11 +180,16 @@ func reflectType(typ *js.Object) *rtype {
180180
fields := typ.Get("fields")
181181
reflectFields := make([]structField, fields.Length())
182182
for i := range reflectFields {
183-
reflectFields[i] = buildStructField(i, fields.Index(i))
183+
f := fields.Index(i)
184+
reflectFields[i] = structField{
185+
name: newName(internalStr(f.Index.Get("name")), internalStr(f.Get("tag")), f.Get("exported").Bool(), f.Get("embedded").Bool()),
186+
typ: reflectType(f.Get("typ")),
187+
offset: uintptr(i),
188+
}
184189
}
185190
setKindType(rt, &structType{
186191
rtype: *rt,
187-
pkgPath: newNameWithoutEmbed(internalStr(typ.Get("pkgPath")), "", false),
192+
pkgPath: newName(internalStr(typ.Get("pkgPath")), "", false, false),
188193
fields: reflectFields,
189194
})
190195
}
@@ -258,10 +263,24 @@ func (n name) name() (s string) { return nameMap[n.bytes].name }
258263
func (n name) tag() (s string) { return nameMap[n.bytes].tag }
259264
func (n name) pkgPath() string { return nameMap[n.bytes].pkgPath }
260265
func (n name) isExported() bool { return nameMap[n.bytes].exported }
266+
func (n name) embedded() bool { return nameMap[n.bytes].embedded }
261267
func (n name) setPkgPath(pkgpath string) {
262268
nameMap[n.bytes].pkgPath = pkgpath
263269
}
264270

271+
func newName(n, tag string, exported, embedded bool) name {
272+
b := new(byte)
273+
nameMap[b] = &nameData{
274+
name: n,
275+
tag: tag,
276+
exported: exported,
277+
embedded: embedded,
278+
}
279+
return name{
280+
bytes: b,
281+
}
282+
}
283+
265284
// newMethodName creates name instance for a method.
266285
//
267286
// Input object is expected to be an entry of the "methods" list of the

compiler/natives/src/reflect/reflect1.18.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

compiler/natives/src/reflect/reflect1.19.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)