Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/lrita/cmap

go 1.18
go 1.19
28 changes: 14 additions & 14 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
type Map[K comparable, V any] struct {
lock sync.Mutex
inode unsafe.Pointer // *inode2
typ *rtype
typ atomic.Pointer[rtype]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use unsafe.Pointer here, or upgrade the minimum dependency in go.mod to a version that supports this type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks.

count int64
}

Expand Down Expand Up @@ -400,23 +400,23 @@ func efaceOf(ep *any) *eface {
}

func (m *Map[K, V]) ehash(i K) uintptr {
if m.typ == nil {
func() {
m.lock.Lock()
defer m.lock.Unlock()
if m.typ == nil {
// if K is interface type, then the direct reflect.TypeOf(K).Kind return reflect.Ptr
if typ := reflect.TypeOf(&i); typ.Elem().Kind() == reflect.Interface {
panic("not support interface type")
}
var e any = i
m.typ = efaceOf(&e).typ
typ := m.typ.Load()
if typ == nil {
m.lock.Lock()
if m.typ.Load() == nil {
// if K is interface type, then the direct reflect.TypeOf(K).Kind return reflect.Ptr
if typ := reflect.TypeOf(&i); typ.Elem().Kind() == reflect.Interface {
panic("not support interface type")
}
}()
var e any = i
m.typ.Store(efaceOf(&e).typ)
}
m.lock.Unlock()
typ = m.typ.Load()
}

var f eface
f.typ = m.typ
f.typ = typ
if f.typ.IsDirectIface() {
f.data = *(*unsafe.Pointer)(unsafe.Pointer(&i))
} else {
Expand Down
Loading