Skip to content

Reduce string copies and allocations when emitting inlined sourcemaps #1550

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dzbarsky
Copy link

No description provided.

func (gen *Generator) Base64DataURL() string {
const prefix = "data:application/json;base64,"
data := gen.bytes()
buf := make([]byte, len(prefix)+base64.StdEncoding.EncodedLen(len(data)))
Copy link
Author

Choose a reason for hiding this comment

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

this can also be done via strings.Builder with Grow and Write if preferred, it's essentially the same unsafe.String trick under the hood

Copy link
Member

Choose a reason for hiding this comment

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

Yes, avoiding unsafe is preferred.

@dzbarsky
Copy link
Author

@microsoft-github-policy-service agre

@dzbarsky
Copy link
Author

@microsoft-github-policy-service agree

@@ -1,11 +1,13 @@
package sourcemap

import (
"encoding/base64"
"encoding/json"
Copy link
Member

Choose a reason for hiding this comment

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

Not really sure why you swapped out the json import?

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.

2 participants