Skip to content

Conversation

scottf
Copy link
Contributor

@scottf scottf commented Oct 8, 2025

No description provided.

lengthMap.put(key, oldLen + checked.len);
serialized = null; // since the data changed, clear this so it's rebuilt
}
CheckState checked = check(key, values);
Copy link
Contributor Author

@scottf scottf Oct 8, 2025

Choose a reason for hiding this comment

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

the check method is a refactor of all the checks and validations, plus bringing everything inline.

int len = key.length();
for (int idx = 0; idx < len; idx++) {
// Check the key to ensure it matches the specification for keys.
int keyLen = key.length();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

instead of repeatedly calling .length

static void checkKey(String key) {
// key cannot be null or empty and contain only printable characters except colon
static CheckState check(String key, Collection<String> values) {
if (key == null || key.isEmpty()) {
Copy link
Contributor Author

@scottf scottf Oct 8, 2025

Choose a reason for hiding this comment

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

the refactor does the key validation. Before, _put did this and then the old checker also did it, meaning it was checked twice. _add did it correctly in the checker.

}
}
list.add(val);
len += keyLen + valLen + 3; // 3 is for the colon, cr and lf
Copy link
Contributor Author

Choose a reason for hiding this comment

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

length is zero if there were only null values

if (opts == null) {
return headers;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if there aren't any opts, just short circuit. This is probably the most common way publish is called.

}
return h.add(key, value);
// this is always an internal header with one value per key
return h.put(key, Collections.singletonList(value));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

switch to put because there will only every be one of each key.

@scottf scottf requested a review from MauriceVanVeen October 8, 2025 18:33
Copy link
Member

@MauriceVanVeen MauriceVanVeen left a comment

Choose a reason for hiding this comment

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

LGTM

@scottf scottf merged commit 9307109 into main Oct 8, 2025
4 checks passed
@scottf scottf deleted the more-header-tuning branch October 8, 2025 20:04
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