MCPcopy
hub / github.com/AlistGo/alist / Load

Method Load

pkg/generic_sync/map.go:103–126  ·  view source on GitHub ↗

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

(key K)

Source from the content-addressed store, hash-verified

101// value is present.
102// The ok result indicates whether value was found in the map.
103func (m *MapOf[K, V]) Load(key K) (value V, ok bool) {
104 read, _ := m.read.Load().(readOnly[K, V])
105 e, ok := read.m[key]
106 if !ok && read.amended {
107 m.mu.Lock()
108 // Avoid reporting a spurious miss if m.dirty got promoted while we were
109 // blocked on m.mu. (If further loads of the same key will not miss, it's
110 // not worth copying the dirty map for this key.)
111 read, _ = m.read.Load().(readOnly[K, V])
112 e, ok = read.m[key]
113 if !ok && read.amended {
114 e, ok = m.dirty[key]
115 // Regardless of whether the entry was present, record a miss: this key
116 // will take the slow path until the dirty map is promoted to the read
117 // map.
118 m.missLocked()
119 }
120 m.mu.Unlock()
121 }
122 if !ok {
123 return value, false
124 }
125 return e.load()
126}
127
128func (m *MapOf[K, V]) Has(key K) bool {
129 _, ok := m.Load(key)

Callers 15

HasMethod · 0.95
ReadMethod · 0.80
SeekMethod · 0.80
createSessionMethod · 0.80
signMethod · 0.80
requestMethod · 0.80
unlockSafeBoxMethod · 0.80
ReadMethod · 0.80
SeekMethod · 0.80
GetMethod · 0.80
ReadMethod · 0.80
WriteMethod · 0.80

Calls 3

missLockedMethod · 0.95
loadMethod · 0.80
UnlockMethod · 0.65

Tested by 1

TestConcurrentRangeFunction · 0.64