Skip to content

Commit

Permalink
Merge pull request #544 from sai-g/field_map_remove_tag
Browse files Browse the repository at this point in the history
Remove tag from field map
  • Loading branch information
ackleymi committed May 8, 2023
2 parents f98268b + d1ac11d commit ff15bcf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions field_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ func (m *FieldMap) SetString(tag Tag, value string) *FieldMap {
return m.SetBytes(tag, []byte(value))
}

// Remove removes a tag from field map.
func (m *FieldMap) Remove(tag Tag) {
m.rwLock.Lock()
defer m.rwLock.Unlock()

delete(m.tagLookup, tag)
}

// Clear purges all fields from field map.
func (m *FieldMap) Clear() {
m.rwLock.Lock()
Expand Down
12 changes: 12 additions & 0 deletions field_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,15 @@ func TestFieldMap_CopyInto(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, "a", s)
}

func TestFieldMap_Remove(t *testing.T) {
var fMap FieldMap
fMap.init()

fMap.SetField(1, FIXString("hello"))
fMap.SetField(2, FIXString("world"))

fMap.Remove(1)
assert.False(t, fMap.Has(1))
assert.True(t, fMap.Has(2))
}

0 comments on commit ff15bcf

Please sign in to comment.