Fix key splitting failures if key contains any parenthesis char#550
Merged
glebm merged 1 commit intoglebm:mainfrom Feb 17, 2024
Merged
Conversation
ed821c8 to
0fdc73f
Compare
For example, if a key contains a '>' or ')' char, but these are not preceded by an opening character, everything after this character was previously considered to be inside parenthesis. This update ensures dots are only escaped if chars are both preceded by parenthesis opening characters, and followed by closing characters
0fdc73f to
61bc4fc
Compare
glebm
reviewed
Feb 16, 2024
| if parts.length + 1 >= max | ||
| parts << key[pos..] unless pos == key.length | ||
| break | ||
| parts = [] |
Owner
There was a problem hiding this comment.
This does a lot more allocations than the previous version.
split_key is called a lot, what's the impact on performance?
Contributor
Author
There was a problem hiding this comment.
It's actually faster on my machine (M1 Macbook Air):
On commit 0b4b483c82664f26c5696fb0f6aa1297356e4683 (latest main):
> Benchmark.measure { 1_000_000.times do ; I18n::Tasks::SplitKey.split_key('a.#{b.c}.d.<e.f>'); end }
#<Benchmark::Tms:0x0000000105396880 @cstime=0.0, @cutime=0.0, @label="", @real=4.406474999999773, @stime=0.005112000000000005, @total=4.400721000000001, @utime=4.395609>
On commit 61bc4fc4c25632798401599f6be6b7a45fef9945 (this PR):
> Benchmark.measure { 1_000_000.times do ; I18n::Tasks::SplitKey.split_key('a.#{b.c}.d.<e.f>'); end }
#<Benchmark::Tms:0x0000000103042190 @cstime=0.0, @cutime=0.0, @label="", @real=3.340463999998974, @stime=0.005928000000000003, @total=3.336179, @utime=3.330251>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note that the complete split_key function has been refactored to be more readable, and a test has been added to check for the failures that occurred previously
Closes #549