@@ -6,7 +6,7 @@ package runtime
6
6
// https://golang.org/src/runtime/map.go
7
7
8
8
import (
9
- "reflect "
9
+ "internal/reflectlite "
10
10
"tinygo"
11
11
"unsafe"
12
12
)
@@ -539,8 +539,8 @@ func hashmapStringDelete(m *hashmap, key string) {
539
539
// a field is exported and thus allows circumventing the type system.
540
540
// The hash function needs it as it also needs to hash unexported struct fields.
541
541
//
542
- //go:linkname valueInterfaceUnsafe reflect .valueInterfaceUnsafe
543
- func valueInterfaceUnsafe (v reflect .Value ) interface {}
542
+ //go:linkname valueInterfaceUnsafe internal/reflectlite .valueInterfaceUnsafe
543
+ func valueInterfaceUnsafe (v reflectlite .Value ) interface {}
544
544
545
545
func hashmapFloat32Hash (ptr unsafe.Pointer , seed uintptr ) uint32 {
546
546
f := * (* uint32 )(ptr )
@@ -561,7 +561,7 @@ func hashmapFloat64Hash(ptr unsafe.Pointer, seed uintptr) uint32 {
561
561
}
562
562
563
563
func hashmapInterfaceHash (itf interface {}, seed uintptr ) uint32 {
564
- x := reflect .ValueOf (itf )
564
+ x := reflectlite .ValueOf (itf )
565
565
if x .RawType () == nil {
566
566
return 0 // nil interface
567
567
}
@@ -574,39 +574,39 @@ func hashmapInterfaceHash(itf interface{}, seed uintptr) uint32 {
574
574
}
575
575
576
576
switch x .RawType ().Kind () {
577
- case reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 :
577
+ case reflectlite .Int , reflectlite .Int8 , reflectlite .Int16 , reflectlite .Int32 , reflectlite .Int64 :
578
578
return hash32 (ptr , x .RawType ().Size (), seed )
579
- case reflect .Bool , reflect .Uint , reflect .Uint8 , reflect .Uint16 , reflect .Uint32 , reflect .Uint64 , reflect .Uintptr :
579
+ case reflectlite .Bool , reflectlite .Uint , reflectlite .Uint8 , reflectlite .Uint16 , reflectlite .Uint32 , reflectlite .Uint64 , reflectlite .Uintptr :
580
580
return hash32 (ptr , x .RawType ().Size (), seed )
581
- case reflect .Float32 :
581
+ case reflectlite .Float32 :
582
582
// It should be possible to just has the contents. However, NaN != NaN
583
583
// so if you're using lots of NaNs as map keys (you shouldn't) then hash
584
584
// time may become exponential. To fix that, it would be better to
585
585
// return a random number instead:
586
586
// https://research.swtch.com/randhash
587
587
return hashmapFloat32Hash (ptr , seed )
588
- case reflect .Float64 :
588
+ case reflectlite .Float64 :
589
589
return hashmapFloat64Hash (ptr , seed )
590
- case reflect .Complex64 :
590
+ case reflectlite .Complex64 :
591
591
rptr , iptr := ptr , unsafe .Add (ptr , 4 )
592
592
return hashmapFloat32Hash (rptr , seed ) ^ hashmapFloat32Hash (iptr , seed )
593
- case reflect .Complex128 :
593
+ case reflectlite .Complex128 :
594
594
rptr , iptr := ptr , unsafe .Add (ptr , 8 )
595
595
return hashmapFloat64Hash (rptr , seed ) ^ hashmapFloat64Hash (iptr , seed )
596
- case reflect .String :
596
+ case reflectlite .String :
597
597
return hashmapStringHash (x .String (), seed )
598
- case reflect .Chan , reflect .Ptr , reflect .UnsafePointer :
598
+ case reflectlite .Chan , reflectlite .Ptr , reflectlite .UnsafePointer :
599
599
// It might seem better to just return the pointer, but that won't
600
600
// result in an evenly distributed hashmap. Instead, hash the pointer
601
601
// like most other types.
602
602
return hash32 (ptr , x .RawType ().Size (), seed )
603
- case reflect .Array :
603
+ case reflectlite .Array :
604
604
var hash uint32
605
605
for i := 0 ; i < x .Len (); i ++ {
606
606
hash ^= hashmapInterfaceHash (valueInterfaceUnsafe (x .Index (i )), seed )
607
607
}
608
608
return hash
609
- case reflect .Struct :
609
+ case reflectlite .Struct :
610
610
var hash uint32
611
611
for i := 0 ; i < x .NumField (); i ++ {
612
612
hash ^= hashmapInterfaceHash (valueInterfaceUnsafe (x .Field (i )), seed )
0 commit comments