| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
| |
fstrings
|
| |
|
| |
|
| |
|
|
|
|
|
|
| |
Using `(raise FooError, "error")` is like forcing a "new scope" around
the `raise` call, it's simpler to just wrap the `raise` arguments with
parentheses just like any other method call would.
|
| |
|
|
|
|
|
|
| |
This reverts commit e9651deea4145f62224af56af027bfbb3e45e4cd.
Now we're having both `=~` and `match?` for these objects, and it's nicer to have explicit tests for both of them
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Applications are not supposed to use require_dependency in their own
code if running in zeitwerk mode, and require_dependency was initially
aliased to require with that use case in mind.
However, there are situations in which you cannot control the mode and
need to be compatible with both. There, you might need require_dependency
in case you are being executed in classic mode. Think about engines that
want to support both modes in their parent applications, for example.
Furthermore, Rails itself loads helpers using require_dependency.
Therefore, we need better compatibility.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
```ruby
class String
def to1(position)
position = [position + length, -1].max if position < 0
self[0, position + 1]
end
def to2(position)
position += size if position < 0
self[0, position + 1] || +""
end
end
Benchmark.ips do |x|
x.report("'foo'.to(1)") { 'foo'.to(1) }
x.report("'foo'.to1(1)") { 'foo'.to1(1) }
x.report("'foo'.to2(1)") { 'foo'.to2(1) }
x.report("'foo'.to(-1)") { 'foo'.to(-1) }
x.report("'foo'.to1(-1)") { 'foo'.to1(-1) }
x.report("'foo'.to2(-1)") { 'foo'.to2(-1) }
x.report("'foo'.to(-10)") { 'foo'.to(-10) }
x.report("'foo'.to1(-10)") { 'foo'.to1(-10) }
x.report("'foo'.to2(-10)") { 'foo'.to2(-10) }
end
```
Result:
```
Warming up --------------------------------------
'foo'.to(1) 199.859k i/100ms
'foo'.to1(1) 220.293k i/100ms
'foo'.to2(1) 221.522k i/100ms
'foo'.to(-1) 205.032k i/100ms
'foo'.to1(-1) 195.837k i/100ms
'foo'.to2(-1) 214.975k i/100ms
'foo'.to(-10) 214.331k i/100ms
'foo'.to1(-10) 182.666k i/100ms
'foo'.to2(-10) 224.696k i/100ms
Calculating -------------------------------------
'foo'.to(1) 4.685M (± 4.2%) i/s - 23.583M in 5.042568s
'foo'.to1(1) 5.233M (± 5.8%) i/s - 26.215M in 5.026778s
'foo'.to2(1) 5.180M (± 5.7%) i/s - 25.918M in 5.020735s
'foo'.to(-1) 4.253M (± 7.0%) i/s - 21.323M in 5.043133s
'foo'.to1(-1) 4.438M (±11.2%) i/s - 21.934M in 5.025751s
'foo'.to2(-1) 4.716M (± 9.8%) i/s - 23.432M in 5.028088s
'foo'.to(-10) 4.678M (± 9.5%) i/s - 23.148M in 5.007379s
'foo'.to1(-10) 4.428M (± 5.1%) i/s - 22.103M in 5.005155s
'foo'.to2(-10) 5.243M (± 4.6%) i/s - 26.289M in 5.024695s
```
|
|\
| |
| | |
Improve String#first and #last performance
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Removes unnecessary conditional and method call for significant
performance improvement. As a side effect, this fixes an unexpected
behavior where passing a limit of 0 would return a frozen string.
This also implements the Rails 6.1 intended behavior with regards to
negative limits, and removes the previous deprecation warnings.
String#first Comparison:
new: 3056515.0 i/s
old: 1943310.2 i/s - 1.57x slower
String#last Comparison:
new: 2691919.0 i/s
old: 1924256.6 i/s - 1.40x slower
(Note: "old" benchmarks have deprecation warnings commented out, for a
more fair comparison.)
|
| |
| |
| |
| | |
We're already running Performance/RegexpMatch cop, but it seems like the cop is not always =~ justice
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
In case a negative position is provided that exceeds the size of the
string, we're relying on -1 returned from max to get 0 length by + 1
and let [] with a 0 length returning "" for us.
E.g. "hello".to(-7), where -7 + 5 size = -2. That's
lower than -1, so we use -1 instead and + 1 would turn it into 0.
Instead allow outer bounds access and always return "".
|
| | |
|
| |
| |
| |
| |
| |
| | |
GB18030 is Unicode compatible and covers all Unicode code points so we can temporarily convert GB18030 strings to UTF-8 to perform the transliteration. After transliterating we want to convert back to GB18030.
In all cases of transcoding, we replace invalid or undefined characters with the default replacement character ("?"). This is in line with the behavior of tidy_bytes which is used on the UTF-8 string before transliterating.
|
| |
| |
| |
| | |
US-ASCII is a subset of UTF-8 so we can temporarily convert US-ASCII strings to UTF-8 to perform the transliteration. After we've converted characters to ASCII representations, we can set the encoding back to US-ASCII to return the same encoding we accepted.
|
| | |
|
| |
| |
| |
| | |
Adds ArgumentErrors to `ActiveSupport::Inflector::transliterate` if a string is with ASCII-8BIT which will raise an error in `unicode_normalize`.
|
|\ \
| | |
| | | |
Avoid extra allocation in String#from and #to
|
| |/
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Removes unnecessary Range object allocations for a significant speed-up.
String#from Comparison:
new: 3378594.0 i/s
old: 2380129.8 i/s - 1.42x slower
String#to Comparison:
new: 2866175.7 i/s
old: 2304406.4 i/s - 1.24x slower
|
| |
| |
| |
| |
| | |
`Messages::Rotator` has `@on_rotation` not `@rotation`.
https://github.com/rails/rails/blob/72bc0806a7b378cd544e8fbf7ab22d74b7913ffb/activesupport/lib/active_support/messages/rotator.rb#L11
|
| | |
|
| |
| |
| |
| |
| |
| | |
Simplifies the surrounding code outside `convert_value`.
Ref: https://github.com/rails/rails/pull/36758
|
| | |
|
|\ \
| | |
| | | |
Merge payload for EventObject subscribers
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
When instrumenting a block of code like:
```ruby
ActiveSupport::Notifications.instrument("process_action.action_controller", raw_paylaod) do |payload|
payload[:view_runtime] = render_view
end
```
If we use an evented subscriber like so:
``` ruby
ActiveSupport::Notifications.subscribe("process_action.action_controller", raw_payload) do |event|
assert event.payload[:view_runtime]
end
```
The code breaks because the underlying EventObject's payload does not have the
`:view_runtime` key added during instrumentation.
This is because the `EventedObject` subscriber calls the `finish` method with the
`payload` of the event at the time it was pushed into the stack, before the
block executes, but we want to call `finish` with the `payload` after the
instrument block executes this way if the `payload` was modified during the block
we have access to it. This is consistent with the other types of subscribers
who don't have this bug.
|
|\ \ \
| | | |
| | | |
| | | | |
Add compact_blank shortcut for reject(&:blank?)
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
I frequently find myself having to .compact but for blank. which means
on an array reject(&:blank?) (this is fine), or,
on a hash `.reject { |_k, v| v.blank? }` which is slightly more
frustrating and i usually write it as .reject(&:blank?) first and am
confused when it's trying to check if the keys are blank.
I've added the analagous .compact_blank! where there's a reject! to
build on (there's also a reject! in Set, but there's no other core_ext
touching Set so i've left that alone)
|
|\ \ \ \
| | | | |
| | | | | |
Avoid unnecessary hash allocation in HashWithIndifferentAccess#convert_value
|
| | | | |
| | | | |
| | | | |
| | | | | |
options
|
|/ / / / |
|
| | | |
| | | |
| | | |
| | | |
| | | | |
Use Fiber.current.__id__ in ActiveSupport::Logger#local_level= in order
to make log level local to Ruby Fibers in addition to Threads.
|
|\ \ \ \
| | | | |
| | | | | |
Introduce a new ActiveSupport::SecureCompareRotator class:
|
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
- This class is used to rotate a previously determined value to a new
one before making the comparions.
We use this at Shopify to rotate Basic Auth crendials but I can
imagine other use cases.
The implementation uses the same `Messages::Rotator` module than
the MessageEncryptor/MessageVerifier class so it works exactly the
same way.
You can use it as follow:
```ruby
rotator = ActiveSupport::SecureCompareRotator.new('new_production_value')
rotator.rotate('previous_production_value')
rotator.secure_compare!('previous_production_value')
```
|
|\ \ \ \ \
| | | | | |
| | | | | | |
Add support for Proc based parameter filtering on arrays of values
|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
Remove extra newline.
Co-Authored-By: Rafael França <rafael@franca.dev>
|
| | | | | | |
|
| | | | | | |
|
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
Based on the way parameters are currently processed, a parameter value of type Hash is recursively processed. For a value of type Array however, the current behavior is to simply return the original array, with no filtering. It is not clear what the expected behavior should be. But, doing nothing seems incorrect, since it bypasses custom Proc based parameter filtering all together for arrays of values. This change processes values of type Array consistently. We map over the values and recursively call value_for_key on them. This still works with values of type Hash, since value_for_key already knows how to process Hash values.
|
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
Based on the way parameters are currently processed, a parameter value of type Hash is recursively processed. For a value of type Array however, the current behavior is to simply return the original array, with no filtering. It is not clear what the expected behavior should be. But, doing nothing seems incorrect, since it bypasses custom Proc based parameter filtering all together for arrays of values. This change introduces a failing test in preparation to add logic that proposes one possible option for the expected behavior with Array values.
|
| | | | | | |
|
| | | | | | |
|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
Exclude missing marshal_dump and _dump methods from being delegated to
an object's delegation target via the delegate_missing_to extension.
This avoids unintentionally adding instance variables to an object
during marshallization, should the delegation target be a method which
would otherwise add them.
In current versions of Ruby, a bug exists in the way objects are
marshalled, allowing for instance variables to be added or removed
during marshallization (see https://bugs.ruby-lang.org/issues/15968).
This results in a corrupted serialized byte stream, causing an object's
instance variables to "leak" into subsequent serialized objects during
demarshallization.
In Rails, this behavior may be triggered when marshalling an object that
uses the delegate_missing_to extension, if the delegation target is a
method which adds or removes instance variables to an object being
marshalled - when calling Marshal.dump(object), Ruby's built in behavior
will check whether the object responds to :marshal_dump or :_dump, which
in turn triggers the delegation target method in the
responds_to_missing? function defined in
activesupport/lib/active_support/core_ext/module/delegation.rb
While future versions of Ruby will resolve this bug by raising a
RuntimeError, the underlying cause of this error may not be readily
apparent when encountered by Rails developers. By excluding marshal_dump
and _dump from being delegated to an object's target, this commit
eliminates a potential cause of unexpected behavior and/or
RuntimeErrors.
Fixes #36522
|
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
`ActiveSupport::Inflector.transliterate`"
|
|\ \ \ \ \ \
| | | | | | |
| | | | | | | |
Make UTF-8 string requirement explicit for `ActiveSupport::Inflector.transliterate`
|
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | | |
It's noted in #34062 that String#parameterize will raise an `Encoding::CompatibilityError` if the string is not UTF-8 encoded. The error is raised as a result of passing the string to `.unicode_normalize`.
This PR raises a higher level `ArgumentError` if the provided string is not UTF-8 and updates documentation to note the encoding requirement.
|
|\ \ \ \ \ \ \
| |/ / / / / /
|/| | | | | | |
Update message verifier documentation [ci skip]
|