Skip to content

Conversation

@c2h5oh
Copy link
Collaborator

@c2h5oh c2h5oh commented Jun 26, 2025

  • deduplicates values
  • uses sets (not sorted sets)
  • faster matching with 0 allocations, slightly slower and slightly more allocations when parsing headers - all in all a net gain
  • arguably cleaner code
  • adds a dependency, but I'll take fast, battle tested code over reinventing sets any day

"strconv"
"strings"

"github.com/scylladb/go-set/strset"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid introducing a new external package?

Can we simply use map[string]struct{}?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could, but if we did I would be copy-pasting significant part of of that package anyway, so I don't think it would be better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not introduce external dependencies to chi core package, unless necessary.

func TestParseHeaderList(t *testing.T) {
h := parseHeaderList("header, second-header, THIRD-HEADER, Numb3r3d-H34d3r, Header_with_underscore Header.with.full.stop")
e := []string{"Header", "Second-Header", "Third-Header", "Numb3r3d-H34d3r", "Header_with_underscore", "Header.with.full.stop"}
if h[0] != e[0] || h[1] != e[1] || h[2] != e[2] || h[3] != e[3] || h[4] != e[4] || h[5] != e[5] {
Copy link
Contributor

Choose a reason for hiding this comment

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

slices.Equal or maps.Equal will do

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.

3 participants