Skip to content

Commit 3ab32da

Browse files
Emyrkjohnstcn
authored andcommitted
reduce the amount of memoery allocated
1 parent 9981291 commit 3ab32da

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

coderd/authz/authztest/set.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ type Role struct {
1111
PermissionSets []iterator
1212
// This is kinda werird, but the first scan should not move anything.
1313
first bool
14+
15+
buffer []*Permission
1416
}
1517

1618
func (r *Role) Each(ea func(set Set)) {
@@ -33,6 +35,7 @@ func NewRole(sets ...iterable) *Role {
3335
ReturnSize: retSize,
3436
Size: size,
3537
PermissionSets: setInterfaces,
38+
buffer: make([]*Permission, retSize),
3639
}
3740
}
3841

@@ -56,6 +59,10 @@ func (s *Role) Next() bool {
5659
}
5760

5861
func (s *Role) Permissions() Set {
62+
var i int
63+
for _, set := range s.PermissionSets {
64+
i += copy(s.buffer[i:], set.Permissions())
65+
}
5966
all := make(Set, 0, s.Size)
6067
for _, set := range s.PermissionSets {
6168
all = append(all, set.Permissions()...)

0 commit comments

Comments
 (0)