diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2017-12-13 14:08:30 +0100 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2017-12-13 14:08:30 +0100 |
commit | 1f408288bd63156212e619e0dc7213551dd853e5 (patch) | |
tree | d500deb4dd48ec1031f9a9c04f84edf06f7c0e99 | |
parent | de8e6592e23a3819266cea5e9999c7c21fdd826f (diff) |
Remove map usage via pointers
Change-Id: Idf2a119e633851ab8e3ddfe17dadca4e96c6a4ac
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
-rw-r--r-- | adapter/mock/mock_adapter.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/adapter/mock/mock_adapter.go b/adapter/mock/mock_adapter.go index 8768725..af54ced 100644 --- a/adapter/mock/mock_adapter.go +++ b/adapter/mock/mock_adapter.go @@ -34,8 +34,8 @@ import ( type VppAdapter struct { callback func(context uint32, msgId uint16, data []byte) - msgNameToIds *map[string]uint16 - msgIDsToName *map[uint16]string + msgNameToIds map[string]uint16 + msgIDsToName map[uint16]string msgIDSeq uint16 binAPITypes map[string]reflect.Type access sync.RWMutex @@ -101,7 +101,7 @@ func (a *VppAdapter) GetMsgNameByID(msgID uint16) (string, bool) { a.access.Lock() defer a.access.Unlock() a.initMaps() - msgName, found := (*a.msgIDsToName)[msgID] + msgName, found := a.msgIDsToName[msgID] return msgName, found } @@ -181,15 +181,15 @@ func (a *VppAdapter) GetMsgID(msgName string, msgCrc string) (uint16, error) { defer a.access.Unlock() a.initMaps() - msgID, found := (*a.msgNameToIds)[msgName] + msgID, found := a.msgNameToIds[msgName] if found { return msgID, nil } a.msgIDSeq++ msgID = a.msgIDSeq - (*a.msgNameToIds)[msgName] = msgID - (*a.msgIDsToName)[msgID] = msgName + a.msgNameToIds[msgName] = msgID + a.msgIDsToName[msgID] = msgName log.Println("VPP GetMessageId ", msgID, " name:", msgName, " crc:", msgCrc) @@ -199,8 +199,8 @@ func (a *VppAdapter) GetMsgID(msgName string, msgCrc string) (uint16, error) { // initMaps initializes internal maps (if not already initialized). func (a *VppAdapter) initMaps() { if a.msgIDsToName == nil { - a.msgIDsToName = &map[uint16]string{} - a.msgNameToIds = &map[string]uint16{} + a.msgIDsToName = map[uint16]string{} + a.msgNameToIds = map[string]uint16{} a.msgIDSeq = 1000 } @@ -222,7 +222,7 @@ func (a *VppAdapter) SendMsg(clientID uint32, data []byte) error { struc.Unpack(buf, &reqHeader) a.access.Lock() - reqMsgName, _ := (*a.msgIDsToName)[reqHeader.VlMsgID] + reqMsgName, _ := a.msgIDsToName[reqHeader.VlMsgID] a.access.Unlock() reply, msgID, finished := replyHandler(MessageDTO{reqHeader.VlMsgID, reqMsgName, |