Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f58cd04e authored by Colin Cross's avatar Colin Cross Committed by android-build-merger
Browse files

Merge "Change type of Once keys to OnceKey"

am: 450bde14

Change-Id: Id4febec2a6cb7d8b1cc58bc0d24480dfa9d8cd12
parents fca445df 450bde14
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ type OncePer struct {

// Once computes a value the first time it is called with a given key per OncePer, and returns the
// value without recomputing when called with the same key.  key must be hashable.
func (once *OncePer) Once(key interface{}, value func() interface{}) interface{} {
func (once *OncePer) Once(key OnceKey, value func() interface{}) interface{} {
	// Fast path: check if the key is already in the map
	if v, ok := once.values.Load(key); ok {
		return v
@@ -50,7 +50,7 @@ func (once *OncePer) Once(key interface{}, value func() interface{}) interface{}

// Get returns the value previously computed with Once for a given key.  If Once has not been called for the given
// key Get will panic.
func (once *OncePer) Get(key interface{}) interface{} {
func (once *OncePer) Get(key OnceKey) interface{} {
	v, ok := once.values.Load(key)
	if !ok {
		panic(fmt.Errorf("Get() called before Once()"))
@@ -60,12 +60,12 @@ func (once *OncePer) Get(key interface{}) interface{} {
}

// OnceStringSlice is the same as Once, but returns the value cast to a []string
func (once *OncePer) OnceStringSlice(key interface{}, value func() []string) []string {
func (once *OncePer) OnceStringSlice(key OnceKey, value func() []string) []string {
	return once.Once(key, func() interface{} { return value() }).([]string)
}

// OnceStringSlice is the same as Once, but returns two values cast to []string
func (once *OncePer) Once2StringSlice(key interface{}, value func() ([]string, []string)) ([]string, []string) {
func (once *OncePer) Once2StringSlice(key OnceKey, value func() ([]string, []string)) ([]string, []string) {
	type twoStringSlice [2][]string
	s := once.Once(key, func() interface{} {
		var s twoStringSlice