Skip to content

Commit d8e56e8

Browse files
committed
Removing some defers from the hot-code path
1 parent 71d79bb commit d8e56e8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

server/service_registry.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,26 @@ func NewServiceRegistry() ServiceRegistry {
2121
// Register registers a new service with a list of references
2222
func (rlh *ServiceRegistry) Register(listName string, svc Service) *ServiceRegistry {
2323
rlh.lock.Lock()
24-
defer rlh.lock.Unlock()
25-
2624
rlh.services[listName] = svc
25+
rlh.lock.Unlock()
26+
2727
return rlh
2828
}
2929

3030
// GetServiceForList returns a service able to handle a specific list
3131
func (rlh ServiceRegistry) GetServiceForList(name string) Service {
3232
rlh.lock.RLock()
33-
defer rlh.lock.RUnlock()
33+
svc := rlh.services[name]
34+
rlh.lock.RUnlock()
3435

35-
return rlh.services[name]
36+
return svc
3637
}
3738

3839
// HasServiceForList returns true only if a service has been registered for a certain list
3940
func (rlh ServiceRegistry) HasServiceForList(name string) bool {
4041
rlh.lock.RLock()
41-
defer rlh.lock.RUnlock()
42-
4342
_, ok := rlh.services[name]
43+
rlh.lock.RUnlock()
44+
4445
return ok
4546
}

0 commit comments

Comments
 (0)