-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[mypyc] Add a special case for str_rprimitive in builder.builtin_len #10710
Conversation
source_str = 'abbc' | ||
b = tuple('s:' + x for x in source_str) | ||
assert b == ('s:a', 's:b', 's:b', 's:c') | ||
|
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.
I made a mistake last week that a
cannot be assigned to Tuple[str...]
.
@@ -350,14 +350,13 @@ L4: | |||
return 1 | |||
|
|||
|
|||
[case testTupleBuiltFromList2] | |||
[case testTupleBuiltFromStr] | |||
def f2(val: str) -> str: |
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.
There is another testTupleBuiltFromList
thus it's redundant.
Can you double check the perf impact by running some quick microbenchmark? |
This branch:
Master branch:
Tested on: def list_from_str() -> None:
s1 = "aaaaa"
n = 0
for i in range(1000):
list = [x for x in s1]
n += len(list)
assert n == 5000, n |
Adding a wrapper function has little impact on performance, since the speed up is based on the optimized list comprehension:
|
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.
Looks good! Thanks for the updates.
Description
Closes mypyc/mypyc#835
str_rpimitive
inbuiltin_len
Test Plan