Skip to content

Commit

Permalink
feat(idpool): removed duplicate code in idpool
Browse files Browse the repository at this point in the history
Signed-off-by: Vemula Venkatesh <[email protected]>
  • Loading branch information
venkyvsp committed Feb 3, 2025
1 parent 80d84fc commit 3837ae7
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions pkg/utils/idpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,9 @@ func (ip *IDPool) GetID(key interface{}) uint32 {

// GetIDWithRef get the mod ptr id from pool with Referenbce
func (ip *IDPool) GetIDWithRef(key interface{}, ref interface{}) (uint32, uint32) {
var ok bool
var id uint32
if id, ok = ip.idsInUse[key]; !ok {
if id = ip.assignid(key); id == 0 {
return 0, 0
}
if id = ip.GetID(key); id == 0 {
return 0, 0
}
if ref != nil {
log.Printf("IDPool: GetID Assigning key : %+v , id %+v for ref %v", id, key, ref)
Expand All @@ -133,11 +130,11 @@ func (ip *IDPool) GetIDWithRef(key interface{}, ref interface{}) (uint32, uint32
func (ip *IDPool) ReleaseID(key interface{}) uint32 {
var ok bool
var id uint32
log.Printf("IDPool:ReleaseID Releasing id for key %v", key)
if id, ok = ip.idsInUse[key]; !ok {
log.Printf("No id to release for key %v", key)
return 0
}
log.Printf("IDPool:ReleaseID Releasing id for key %v", key)
delete(ip.idsInUse, key)
ip.idsForReuse[key] = id
log.Printf("IDPool:ReleaseID Id %v has been released", id)
Expand All @@ -146,13 +143,11 @@ func (ip *IDPool) ReleaseID(key interface{}) uint32 {

// ReleaseIDWithRef get the reference id
func (ip *IDPool) ReleaseIDWithRef(key interface{}, ref interface{}) (uint32, uint32) {
var ok bool
var id uint32
log.Printf("IDPool:ReleaseIDWithRef Releasing id for key %v", key)
if id, ok = ip.idsInUse[key]; !ok {
log.Printf("No id to release for key %v", key)
if id = ip.ReleaseID(key); id == 0 {
return 0, 0
}
log.Printf("IDPool:ReleaseIDWithRef Releasing id for key %v", key)
refSet := ip.refs[id]
if !reflect.ValueOf(refSet).IsZero() && !reflect.ValueOf(ref).IsZero() {
delete(refSet, ref)
Expand Down

0 comments on commit 3837ae7

Please sign in to comment.