Skip to content
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

Limit downcasing work for String Time month args #2418

Merged
merged 2 commits into from
Feb 19, 2023

Conversation

lopopolo
Copy link
Member

All valid string arguments to Time.new for the month are 3 ASCII characters. In the event that a very long string is passed, the existing implementation will do a lot of work downcasing the string that is ultimately discarded.

Short circuit this by extracting the first 3 bytes from the captured Vec and only downcasing those.

Followup to #2413.

@lopopolo lopopolo added A-ruby-core Area: Ruby Core types. A-performance Area: Performance improvements and optimizations. labels Feb 19, 2023
@lopopolo lopopolo requested a review from b-n February 19, 2023 19:54
Copy link
Member

@b-n b-n left a comment

Choose a reason for hiding this comment

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

Ah yes, very good point. It's the slice for the downcase, not the slice that is later used for future Kernel#Integer things. Good catch!

All valid string arguments to `Time.new` for the month are 3 ASCII
characters. In the event that a very long string is passed, the existing
implementation will do a lot of work downcasing the string that is
ultimately discarded.

Short circuit this by extracting the first 3 bytes from the captured
`Vec` and only downcasing those.
@lopopolo lopopolo force-pushed the lopopolo/time-string-month-arg-dos-protection branch from 7588248 to 8d91688 Compare February 19, 2023 20:15
@lopopolo lopopolo merged commit 8412300 into trunk Feb 19, 2023
@lopopolo lopopolo deleted the lopopolo/time-string-month-arg-dos-protection branch February 19, 2023 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-performance Area: Performance improvements and optimizations. A-ruby-core Area: Ruby Core types.
Development

Successfully merging this pull request may close these issues.

None yet

2 participants