Skip to content

Commit fbf012b

Browse files
cuishuanggopherbot
authored andcommitted
all: use reflect.TypeFor instead of reflect.TypeOf
For golang/go#60088. Change-Id: Ifbea6ba534dd6037dff028c0a52b210fc0076ae1 Reviewed-on: https://go-review.googlesource.com/c/text/+/709196 Reviewed-by: Sean Liao <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: David Chase <[email protected]> Auto-Submit: Sean Liao <[email protected]>
1 parent c6abd03 commit fbf012b

File tree

8 files changed

+11
-14
lines changed

8 files changed

+11
-14
lines changed

collate/build/contract.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func print(t *colltab.ContractTrieSet, w io.Writer, name string) (n, size int, e
282282

283283
update3(printArray(*t, w, name))
284284
update2(fmt.Fprintf(w, "var %sContractTrieSet = ", name))
285-
update3(printStruct(*t, w, name))
285+
update3(printStruct(w, name))
286286
update2(fmt.Fprintln(w))
287287
return
288288
}
@@ -305,8 +305,8 @@ func printArray(ct colltab.ContractTrieSet, w io.Writer, name string) (n, size i
305305
return
306306
}
307307

308-
func printStruct(ct colltab.ContractTrieSet, w io.Writer, name string) (n, size int, err error) {
308+
func printStruct(w io.Writer, name string) (n, size int, err error) {
309309
n, err = fmt.Fprintf(w, "colltab.ContractTrieSet( %sCTEntries[:] )", name)
310-
size = int(reflect.TypeOf(ct).Size())
310+
size = int(reflect.TypeFor[colltab.ContractTrieSet]().Size())
311311
return
312312
}

collate/build/table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func printColElems(w io.Writer, a []uint32, name string) (n, sz int, err error)
6464
err = e
6565
}
6666
}
67-
sz = len(a) * int(reflect.TypeOf(uint32(0)).Size())
67+
sz = len(a) * int(reflect.TypeFor[uint32]().Size())
6868
p("// %s: %d entries, %d bytes\n", name, len(a), sz)
6969
p("var %s = [%d]uint32 {", name, len(a))
7070
for i, c := range a {

collate/build/trie.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,6 @@ func (t *trie) printArrays(w io.Writer, name string) (n, size int, err error) {
285285
func (t *trie) printStruct(w io.Writer, handle *trieHandle, name string) (n, sz int, err error) {
286286
const msg = "trie{ %sLookup[%d:], %sValues[%d:], %sLookup[:], %sValues[:]}"
287287
n, err = fmt.Fprintf(w, msg, name, handle.lookupStart*blockSize, name, handle.valueStart*blockSize, name, name)
288-
sz += int(reflect.TypeOf(trie{}).Size())
288+
sz += int(reflect.TypeFor[trie]().Size())
289289
return
290290
}

internal/cldrtree/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func generate(b *Builder, t *Tree, w *gen.CodeWriter) error {
5050
fmt.Fprintf(w, "bucket%d,\n", i)
5151
}
5252
fmt.Fprint(w, "}\n\n")
53-
w.Size += int(reflect.TypeOf("").Size()) * len(t.Buckets)
53+
w.Size += int(reflect.TypeFor[string]().Size()) * len(t.Buckets)
5454

5555
// Generate string buckets.
5656
for i, bucket := range t.Buckets {

internal/language/compact/language_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ func mustParse(s string) Tag {
2020
}
2121

2222
func TestTagSize(t *testing.T) {
23-
id := Tag{}
24-
typ := reflect.TypeOf(id)
23+
typ := reflect.TypeFor[Tag]()
2524
if typ.Size() > 24 {
2625
t.Errorf("size of Tag was %d; want 24", typ.Size())
2726
}
2827
}
2928

3029
func TestNoPublic(t *testing.T) {
31-
noExportedField(t, reflect.TypeOf(Tag{}))
30+
noExportedField(t, reflect.TypeFor[Tag]())
3231
}
3332

3433
func noExportedField(t *testing.T, typ reflect.Type) {

internal/language/language_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import (
1212
)
1313

1414
func TestTagSize(t *testing.T) {
15-
id := Tag{}
16-
typ := reflect.TypeOf(id)
15+
typ := reflect.TypeFor[Tag]()
1716
if typ.Size() > 32 {
1817
t.Errorf("size of Tag was %d; want <= 32", typ.Size())
1918
}

language/language_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010
)
1111

1212
func TestTagSize(t *testing.T) {
13-
id := Tag{}
14-
typ := reflect.TypeOf(id)
13+
typ := reflect.TypeFor[Tag]()
1514
if typ.Size() > 24 {
1615
t.Errorf("size of Tag was %d; want 24", typ.Size())
1716
}

unicode/cldr/slice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func MakeSlice(slicePtr interface{}) Slice {
3636
if sl.Kind() != reflect.Slice {
3737
panic(fmt.Sprintf("MakeSlice: argument must point to a slice, found %v", sl.Type()))
3838
}
39-
intf := reflect.TypeOf((*Elem)(nil)).Elem()
39+
intf := reflect.TypeFor[Elem]()
4040
if !sl.Type().Elem().Implements(intf) {
4141
panic(fmt.Sprintf("MakeSlice: element type of slice (%v) does not implement Elem", sl.Type().Elem()))
4242
}

0 commit comments

Comments
 (0)