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

Ordered kv's in dumps #463

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

Conversation

Andrew-Morozko
Copy link

I was writing a serializer/deserializer for goldmark AST and was comparing .Dump's output to quickly check that AST survives the roundtrip encoding intact. But since DumpHelper uses Golang's map for the kv's, the output is not deterministic (kv's are swapped randomly).

This PR solves this (admittedly very niche) issue by sorting the kv's by key before printing them out. I used sort.Slice instead of more modern slices.Sort to preserve the minimal supported go version.

I don't think that this issue is worth the pain of changing DumpHelper's signature to use slices for kv, especially since it is a public func, but perhaps it's worth the tiny inefficiency of sorting the values. What do you think?

P.S.: thanks for the great library!

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.

1 participant