Skip to content

Commit

Permalink
Convert intern interface{} to string
Browse files Browse the repository at this point in the history
  • Loading branch information
zalegrala committed Aug 6, 2024
1 parent 90def69 commit 82789ca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/intern/intern.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import "sync"

// A Value pointer is the handle to an underlying comparable value.
type Value struct {
cmpVal interface{}
cmpVal string
}

// Get returns the comparable value passed to the Get func that returned v.
func (v *Value) Get() interface{} { return v.cmpVal }
func (v *Value) Get() string { return v.cmpVal }

// Our pool of interned values and a lock to serialize access.
var (
mu sync.Mutex
val = map[interface{}]*Value{}
val = map[string]*Value{}
)

// Get returns a pointer representing the comparable value cmpVal.
Expand All @@ -24,7 +24,7 @@ var (
// Note that Get returns a *Value so we only return one word of data
// to the caller, despite potentially storing a large amount of data
// within the Value itself.
func Get(cmpVal interface{}) *Value {
func Get(cmpVal string) *Value {
mu.Lock()
defer mu.Unlock()

Expand Down
4 changes: 2 additions & 2 deletions pkg/intern/intern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestBasics(t *testing.T) {
a1 := x.Get()
a2 := y.Get()

p1 := fmt.Sprintf("%08x\n", stringAddr(a1.(string)))
p2 := fmt.Sprintf("%08x\n", stringAddr(a2.(string)))
p1 := fmt.Sprintf("%08x\n", stringAddr(a1))
p2 := fmt.Sprintf("%08x\n", stringAddr(a2))
require.Equal(t, p1, p2)
}

Expand Down
4 changes: 2 additions & 2 deletions tempodb/backend/block_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ func (b *BlockMeta) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
b.Version = intern.Get(b.Version).Get().(string)
b.TenantID = intern.Get(b.TenantID).Get().(string)
b.Version = intern.Get(b.Version).Get()
b.TenantID = intern.Get(b.TenantID).Get()

return nil
}
Expand Down

0 comments on commit 82789ca

Please sign in to comment.