Skip to content

Commit

Permalink
fix: expose extensions clone method
Browse files Browse the repository at this point in the history
  • Loading branch information
shaj13 committed Feb 3, 2021
1 parent 70a0c81 commit 5529aa7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions auth/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,25 @@ func (exts Extensions) Has(key string) bool {
_, ok := exts[key]
return ok
}

// Clone returns a copy of extensions or nil if extensions is nil.
func (exts Extensions) Clone() Extensions {
if exts == nil {
return nil
}

// Find total number of values.
nv := 0
for _, v := range exts {
nv += len(v)
}
sv := make([]string, nv) // shared backing array for extensions values
cloned := make(Extensions, len(exts))
for k, v := range exts {
n := copy(sv, v)
cloned[k] = sv[:n:n]
sv = sv[n:]
}
return exts

}

0 comments on commit 5529aa7

Please sign in to comment.