Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse buffers using a pool #95

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JensRantil
Copy link
Contributor

Fixes a TODO. Worth it?

There are various approaches to it, though:

 * Have a buffer for each `Email` instance. This would make `Email` not
   being thread-safe anymore.
 * Have a `sync.Pool` containing `bytes.Buffer` instances. This is
   probably a better approach with fewer surprises for users of this
   library. Assuming that this would be a non-exported field on `Email`,
   this would mean that `EMail` can't be instantiated using `Email{...}`
   anymore, which might not be what we want? At least it'll be a
   compilation error, though. Workaround for this issue would be to use
   a `sync.Once` to make sure to instantiate the pool.
Reduces memory allocation and fixes a TODO.
@@ -201,7 +236,7 @@ func parseMIMEParts(hs textproto.MIMEHeader, b io.Reader) ([]*part, error) {
return ps, err
}
if strings.HasPrefix(subct, "multipart/") {
sps, err := parseMIMEParts(p.Header, p)
sps, err := parseMIMEParts(p.Header, p, bufPool)
if err != nil {
return ps, err
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also hand back when returning?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant