-
Notifications
You must be signed in to change notification settings - Fork 183
Header fine tuning #1451
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
Header fine tuning #1451
Conversation
lengthMap.put(key, oldLen + checked.len); | ||
serialized = null; // since the data changed, clear this so it's rebuilt | ||
} | ||
CheckState checked = check(key, values); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; | ||
} | ||
|
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.