Skip to content

Commit

Permalink
Refactor a couple parts of the boundary random sourcing
Browse files Browse the repository at this point in the history
Signed-off-by: James Hillyerd <james@hillyerd.com>
  • Loading branch information
jhillyerd committed Feb 15, 2023
1 parent 65ae7bc commit 4f28904
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
16 changes: 5 additions & 11 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,21 +400,15 @@ func (p MailBuilder) Build() (*Part, error) {
}
}
if r := p.randSource; r != nil {
root.propagateRand(r)
// Traverse all parts, discard match result.
_ = root.DepthMatchAll(func(part *Part) bool {
part.randSource = r
return false
})
}
return root, nil
}

func (p *Part) propagateRand(rand rand.Source) {
p.randSource = rand
for _, x := range []*Part{p.FirstChild, p.NextSibling} {
if x == nil {
continue
}
x.propagateRand(rand)
}
}

// SendWithReversePath encodes the message and sends it via the specified Sender.
func (p MailBuilder) SendWithReversePath(sender Sender, from string) error {
buf := &bytes.Buffer{}
Expand Down
5 changes: 2 additions & 3 deletions internal/stringutil/rand_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ func init() {
// NewLockedSource creates a source of randomness using the given seed.
func NewLockedSource(seed int64) rand.Source64 {
return &lockedSource{
lock: new(sync.Mutex),
s: rand.NewSource(seed).(rand.Source64),
s: rand.NewSource(seed).(rand.Source64),
}
}

type lockedSource struct {
lock sync.Locker
lock sync.Mutex
s rand.Source64
}

Expand Down

0 comments on commit 4f28904

Please sign in to comment.