mirror of https://github.com/golang/go.git
internal/persistent: change map to use set/get as method names
Purely a style change, no expected behavior difference. Change-Id: Ib882eb54537126b31d20dde65c4a517d5452a8b0 Reviewed-on: https://go-review.googlesource.com/c/tools/+/413661 gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
22ab2538d4
commit
2994e99415
|
|
@ -34,8 +34,8 @@ func (m filesMap) Destroy() {
|
|||
m.impl.Destroy()
|
||||
}
|
||||
|
||||
func (m filesMap) Load(key span.URI) (source.VersionedFileHandle, bool) {
|
||||
value, ok := m.impl.Load(key)
|
||||
func (m filesMap) Get(key span.URI) (source.VersionedFileHandle, bool) {
|
||||
value, ok := m.impl.Get(key)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
|
@ -48,8 +48,8 @@ func (m filesMap) Range(do func(key span.URI, value source.VersionedFileHandle))
|
|||
})
|
||||
}
|
||||
|
||||
func (m filesMap) Store(key span.URI, value source.VersionedFileHandle) {
|
||||
m.impl.Store(key, value, nil)
|
||||
func (m filesMap) Set(key span.URI, value source.VersionedFileHandle) {
|
||||
m.impl.Set(key, value, nil)
|
||||
}
|
||||
|
||||
func (m filesMap) Delete(key span.URI) {
|
||||
|
|
@ -88,8 +88,8 @@ func (m goFilesMap) Destroy() {
|
|||
m.impl.Destroy()
|
||||
}
|
||||
|
||||
func (m goFilesMap) Load(key parseKey) (*parseGoHandle, bool) {
|
||||
value, ok := m.impl.Load(key)
|
||||
func (m goFilesMap) Get(key parseKey) (*parseGoHandle, bool) {
|
||||
value, ok := m.impl.Get(key)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
|
@ -102,8 +102,8 @@ func (m goFilesMap) Range(do func(key parseKey, value *parseGoHandle)) {
|
|||
})
|
||||
}
|
||||
|
||||
func (m goFilesMap) Store(key parseKey, value *parseGoHandle, release func()) {
|
||||
m.impl.Store(key, value, func(key, value interface{}) {
|
||||
func (m goFilesMap) Set(key parseKey, value *parseGoHandle, release func()) {
|
||||
m.impl.Set(key, value, func(key, value interface{}) {
|
||||
release()
|
||||
})
|
||||
}
|
||||
|
|
@ -134,8 +134,8 @@ func (m parseKeysByURIMap) Destroy() {
|
|||
m.impl.Destroy()
|
||||
}
|
||||
|
||||
func (m parseKeysByURIMap) Load(key span.URI) ([]parseKey, bool) {
|
||||
value, ok := m.impl.Load(key)
|
||||
func (m parseKeysByURIMap) Get(key span.URI) ([]parseKey, bool) {
|
||||
value, ok := m.impl.Get(key)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
|
@ -148,8 +148,8 @@ func (m parseKeysByURIMap) Range(do func(key span.URI, value []parseKey)) {
|
|||
})
|
||||
}
|
||||
|
||||
func (m parseKeysByURIMap) Store(key span.URI, value []parseKey) {
|
||||
m.impl.Store(key, value, nil)
|
||||
func (m parseKeysByURIMap) Set(key span.URI, value []parseKey) {
|
||||
m.impl.Set(key, value, nil)
|
||||
}
|
||||
|
||||
func (m parseKeysByURIMap) Delete(key span.URI) {
|
||||
|
|
|
|||
|
|
@ -673,7 +673,7 @@ func (s *snapshot) transitiveReverseDependencies(id PackageID, ids map[PackageID
|
|||
func (s *snapshot) getGoFile(key parseKey) *parseGoHandle {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if result, ok := s.goFiles.Load(key); ok {
|
||||
if result, ok := s.goFiles.Get(key); ok {
|
||||
return result
|
||||
}
|
||||
return nil
|
||||
|
|
@ -682,14 +682,14 @@ func (s *snapshot) getGoFile(key parseKey) *parseGoHandle {
|
|||
func (s *snapshot) addGoFile(key parseKey, pgh *parseGoHandle, release func()) *parseGoHandle {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if result, ok := s.goFiles.Load(key); ok {
|
||||
if result, ok := s.goFiles.Get(key); ok {
|
||||
release()
|
||||
return result
|
||||
}
|
||||
s.goFiles.Store(key, pgh, release)
|
||||
keys, _ := s.parseKeysByURI.Load(key.file.URI)
|
||||
s.goFiles.Set(key, pgh, release)
|
||||
keys, _ := s.parseKeysByURI.Get(key.file.URI)
|
||||
keys = append([]parseKey{key}, keys...)
|
||||
s.parseKeysByURI.Store(key.file.URI, keys)
|
||||
s.parseKeysByURI.Set(key.file.URI, keys)
|
||||
return pgh
|
||||
}
|
||||
|
||||
|
|
@ -1326,7 +1326,7 @@ func (s *snapshot) FindFile(uri span.URI) source.VersionedFileHandle {
|
|||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
result, _ := s.files.Load(f.URI())
|
||||
result, _ := s.files.Get(f.URI())
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
@ -1349,7 +1349,7 @@ func (s *snapshot) GetFile(ctx context.Context, uri span.URI) (source.FileHandle
|
|||
}
|
||||
|
||||
func (s *snapshot) getFileLocked(ctx context.Context, f *fileBase) (source.VersionedFileHandle, error) {
|
||||
if fh, ok := s.files.Load(f.URI()); ok {
|
||||
if fh, ok := s.files.Get(f.URI()); ok {
|
||||
return fh, nil
|
||||
}
|
||||
|
||||
|
|
@ -1358,7 +1358,7 @@ func (s *snapshot) getFileLocked(ctx context.Context, f *fileBase) (source.Versi
|
|||
return nil, err
|
||||
}
|
||||
closed := &closedFile{fh}
|
||||
s.files.Store(f.URI(), closed)
|
||||
s.files.Set(f.URI(), closed)
|
||||
return closed, nil
|
||||
}
|
||||
|
||||
|
|
@ -1383,7 +1383,7 @@ func (s *snapshot) openFiles() []source.VersionedFileHandle {
|
|||
}
|
||||
|
||||
func (s *snapshot) isOpenLocked(uri span.URI) bool {
|
||||
fh, _ := s.files.Load(uri)
|
||||
fh, _ := s.files.Get(uri)
|
||||
_, open := fh.(*overlay)
|
||||
return open
|
||||
}
|
||||
|
|
@ -1748,7 +1748,7 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
|
|||
}
|
||||
|
||||
for uri := range changes {
|
||||
keys, ok := result.parseKeysByURI.Load(uri)
|
||||
keys, ok := result.parseKeysByURI.Get(uri)
|
||||
if ok {
|
||||
for _, key := range keys {
|
||||
result.goFiles.Delete(key)
|
||||
|
|
@ -1806,7 +1806,7 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
|
|||
}
|
||||
|
||||
// The original FileHandle for this URI is cached on the snapshot.
|
||||
originalFH, _ := s.files.Load(uri)
|
||||
originalFH, _ := s.files.Get(uri)
|
||||
var originalOpen, newOpen bool
|
||||
_, originalOpen = originalFH.(*overlay)
|
||||
_, newOpen = change.fileHandle.(*overlay)
|
||||
|
|
@ -1853,7 +1853,7 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
|
|||
if !change.exists {
|
||||
result.files.Delete(uri)
|
||||
} else {
|
||||
result.files.Store(uri, change.fileHandle)
|
||||
result.files.Set(uri, change.fileHandle)
|
||||
}
|
||||
|
||||
// Make sure to remove the changed file from the unloadable set.
|
||||
|
|
@ -2197,7 +2197,7 @@ func metadataChanges(ctx context.Context, lockedSnapshot *snapshot, oldFH, newFH
|
|||
// lockedSnapshot must be locked.
|
||||
func peekOrParse(ctx context.Context, lockedSnapshot *snapshot, fh source.FileHandle, mode source.ParseMode) (*source.ParsedGoFile, error) {
|
||||
key := parseKey{file: fh.FileIdentity(), mode: mode}
|
||||
if pgh, ok := lockedSnapshot.goFiles.Load(key); ok {
|
||||
if pgh, ok := lockedSnapshot.goFiles.Get(key); ok {
|
||||
cached := pgh.handle.Cached(lockedSnapshot.generation)
|
||||
if cached != nil {
|
||||
cached := cached.(*parseGoData)
|
||||
|
|
|
|||
|
|
@ -140,9 +140,9 @@ func (node *mapNode) forEach(f func(key, value interface{})) {
|
|||
node.right.forEach(f)
|
||||
}
|
||||
|
||||
// Load returns the value stored in the map for a key, or nil if no entry is
|
||||
// present. The ok result indicates whether an entry was found in the map.
|
||||
func (pm *Map) Load(key interface{}) (interface{}, bool) {
|
||||
// Get returns the map value associated with the specified key, or nil if no entry
|
||||
// is present. The ok result indicates whether an entry was found in the map.
|
||||
func (pm *Map) Get(key interface{}) (interface{}, bool) {
|
||||
node := pm.root
|
||||
for node != nil {
|
||||
if pm.less(key, node.key) {
|
||||
|
|
@ -156,10 +156,10 @@ func (pm *Map) Load(key interface{}) (interface{}, bool) {
|
|||
return nil, false
|
||||
}
|
||||
|
||||
// Store sets the value for a key.
|
||||
// Set updates the value associated with the specified key.
|
||||
// If release is non-nil, it will be called with entry's key and value once the
|
||||
// key is no longer contained in the map or any clone.
|
||||
func (pm *Map) Store(key, value interface{}, release func(key, value interface{})) {
|
||||
func (pm *Map) Set(key, value interface{}, release func(key, value interface{})) {
|
||||
first := pm.root
|
||||
second := newNodeWithRef(key, value, release)
|
||||
pm.root = union(first, second, pm.less, true)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func TestSimpleMap(t *testing.T) {
|
|||
|
||||
m3 := m1.clone()
|
||||
validateRef(t, m1, m3)
|
||||
m3.insert(t, 8, 8)
|
||||
m3.set(t, 8, 8)
|
||||
validateRef(t, m1, m3)
|
||||
m3.destroy()
|
||||
|
||||
|
|
@ -48,15 +48,15 @@ func TestSimpleMap(t *testing.T) {
|
|||
})
|
||||
|
||||
validateRef(t, m1)
|
||||
m1.insert(t, 1, 1)
|
||||
m1.set(t, 1, 1)
|
||||
validateRef(t, m1)
|
||||
m1.insert(t, 2, 2)
|
||||
m1.set(t, 2, 2)
|
||||
validateRef(t, m1)
|
||||
m1.insert(t, 3, 3)
|
||||
m1.set(t, 3, 3)
|
||||
validateRef(t, m1)
|
||||
m1.remove(t, 2)
|
||||
validateRef(t, m1)
|
||||
m1.insert(t, 6, 6)
|
||||
m1.set(t, 6, 6)
|
||||
validateRef(t, m1)
|
||||
|
||||
assertSameMap(t, deletedEntries, map[mapEntry]struct{}{
|
||||
|
|
@ -66,25 +66,25 @@ func TestSimpleMap(t *testing.T) {
|
|||
|
||||
m2 := m1.clone()
|
||||
validateRef(t, m1, m2)
|
||||
m1.insert(t, 6, 60)
|
||||
m1.set(t, 6, 60)
|
||||
validateRef(t, m1, m2)
|
||||
m1.remove(t, 1)
|
||||
validateRef(t, m1, m2)
|
||||
|
||||
for i := 10; i < 14; i++ {
|
||||
m1.insert(t, i, i)
|
||||
m1.set(t, i, i)
|
||||
validateRef(t, m1, m2)
|
||||
}
|
||||
|
||||
m1.insert(t, 10, 100)
|
||||
m1.set(t, 10, 100)
|
||||
validateRef(t, m1, m2)
|
||||
|
||||
m1.remove(t, 12)
|
||||
validateRef(t, m1, m2)
|
||||
|
||||
m2.insert(t, 4, 4)
|
||||
m2.set(t, 4, 4)
|
||||
validateRef(t, m1, m2)
|
||||
m2.insert(t, 5, 5)
|
||||
m2.set(t, 5, 5)
|
||||
validateRef(t, m1, m2)
|
||||
|
||||
m1.destroy()
|
||||
|
|
@ -100,7 +100,7 @@ func TestSimpleMap(t *testing.T) {
|
|||
{key: 13, value: 13}: {},
|
||||
})
|
||||
|
||||
m2.insert(t, 7, 7)
|
||||
m2.set(t, 7, 7)
|
||||
validateRef(t, m2)
|
||||
|
||||
m2.destroy()
|
||||
|
|
@ -124,7 +124,7 @@ func TestRandomMap(t *testing.T) {
|
|||
keys := make([]int, 0, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
key := rand.Int()
|
||||
m.insert(t, key, key)
|
||||
m.set(t, key, key)
|
||||
keys = append(keys, key)
|
||||
|
||||
if i%10 == 1 {
|
||||
|
|
@ -245,9 +245,9 @@ func validateNode(t *testing.T, node *mapNode, less func(a, b interface{}) bool)
|
|||
validateNode(t, node.right, less)
|
||||
}
|
||||
|
||||
func (vm *validatedMap) insert(t *testing.T, key, value int) {
|
||||
func (vm *validatedMap) set(t *testing.T, key, value int) {
|
||||
vm.seen[mapEntry{key: key, value: value}] = struct{}{}
|
||||
vm.impl.Store(key, value, func(deletedKey, deletedValue interface{}) {
|
||||
vm.impl.Set(key, value, func(deletedKey, deletedValue interface{}) {
|
||||
if deletedKey != key || deletedValue != value {
|
||||
t.Fatalf("unexpected passed in deleted entry: %v/%v, expected: %v/%v", deletedKey, deletedValue, key, value)
|
||||
}
|
||||
|
|
@ -256,9 +256,9 @@ func (vm *validatedMap) insert(t *testing.T, key, value int) {
|
|||
vm.expected[key] = value
|
||||
vm.validate(t)
|
||||
|
||||
loadValue, ok := vm.impl.Load(key)
|
||||
if !ok || loadValue != value {
|
||||
t.Fatalf("unexpected load result after insertion, key: %v, expected: %v, got: %v (%v)", key, value, loadValue, ok)
|
||||
gotValue, ok := vm.impl.Get(key)
|
||||
if !ok || gotValue != value {
|
||||
t.Fatalf("unexpected get result after insertion, key: %v, expected: %v, got: %v (%v)", key, value, gotValue, ok)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -267,9 +267,9 @@ func (vm *validatedMap) remove(t *testing.T, key int) {
|
|||
delete(vm.expected, key)
|
||||
vm.validate(t)
|
||||
|
||||
loadValue, ok := vm.impl.Load(key)
|
||||
gotValue, ok := vm.impl.Get(key)
|
||||
if ok {
|
||||
t.Fatalf("unexpected load result after removal, key: %v, got: %v", key, loadValue)
|
||||
t.Fatalf("unexpected get result after removal, key: %v, got: %v", key, gotValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue