Skip to content

Commit

Permalink
make NormalizeBidderName to do faster lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
gargcreation1992 committed Sep 25, 2023
1 parent b9c2614 commit 996dee0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions openrtb_ext/bidders.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func SetAliasBidderName(aliasBidderName string, parentBidderName BidderName) err
aliasBidder := BidderName(aliasBidderName)
coreBidderNames = append(coreBidderNames, aliasBidder)
aliasBidderToParent[aliasBidder] = parentBidderName
bidderNameLookup[strings.ToLower(aliasBidderName)] = aliasBidder
return nil
}

Expand Down Expand Up @@ -564,11 +565,11 @@ var bidderNameLookup = func() map[string]BidderName {
lookup[bidderNameLower] = name
}
return lookup
}
}()

func NormalizeBidderName(name string) (BidderName, bool) {
nameLower := strings.ToLower(name)
bidderName, exists := bidderNameLookup()[nameLower]
bidderName, exists := bidderNameLookup[nameLower]
return bidderName, exists
}

Expand Down
2 changes: 2 additions & 0 deletions openrtb_ext/bidders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"os"
"strings"
"testing"
"testing/fstest"

Expand Down Expand Up @@ -148,6 +149,7 @@ func TestSetAliasBidderName(t *testing.T) {
} else {
assert.Contains(t, CoreBidderNames(), BidderName(test.aliasBidderName))
assert.Contains(t, aliasBidderToParent, BidderName(test.aliasBidderName))
assert.Contains(t, bidderNameLookup, strings.ToLower(test.aliasBidderName))
}
}

Expand Down

0 comments on commit 996dee0

Please sign in to comment.