-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-34002: Minor efficiency and clarity improvements in email package. #7999
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
Changes from all commits
d8bc2c0
51e14f8
c6168d1
b7e4749
4c61d82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -259,21 +259,13 @@ def decode_params(params): | |
|
|
||
| params is a sequence of 2-tuples containing (param name, string value). | ||
| """ | ||
| # Copy params so we don't mess with the original | ||
| params = params[:] | ||
| new_params = [] | ||
| new_params = [params[0]] | ||
| # Map parameter's name to a list of continuations. The values are a | ||
| # 3-tuple of the continuation number, the string value, and a flag | ||
| # specifying whether a particular segment is %-encoded. | ||
| rfc2231_params = {} | ||
| name, value = params.pop(0) | ||
| new_params.append((name, value)) | ||
| while params: | ||
| name, value = params.pop(0) | ||
| if name.endswith('*'): | ||
| encoded = True | ||
| else: | ||
| encoded = False | ||
| for name, value in params[1:]: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. The real benefit is avoiding repeated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the code can be made more optimal if avoid a copy.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks to me that the final value of 'encoded' only depends on the final value of name. If so, the loop is equivalent to Otherwise, one can skip-iterate without copying with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each iteration of the loop uses the |
||
| encoded = name.endswith('*') | ||
| value = unquote(value) | ||
| mo = rfc2231_continuation.match(name) | ||
| if mo: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Improve efficiency in parts of email package by changing while-pop to a for | ||
| loop, using isdisjoint instead of set intersections. |
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.
What if
params[0]is not a 2-tuple?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.
That's possible for the first params element, though the others are implicitly checked by the unpacking for-loop.
Looking at the usage of
decode_params, it's only use is inemail.message._get_params_preservewhich in turn has 3 call sites. All 3 calls unpack the elements as(k, v)pairs. The bad data would cause an immediate error, given how the method is used. The error would be the same as today, though the traceback would not be as deep.If that's not satisfactory, I'll revert to: