Reverts a change from
2327ebfdc6
which can overwrite `test_order` that may have been manually set in
config. This can cause a situation where the user is depending on a
particular `test_order` but is unknowingly forced into another.
Sdoc 2.1.0 works better on mobile and has improvements for SEO and
Lighthouse.
Changelog:
* #154 Make panel responsive for mobile.
* #153 Add viewport metatag to views for improved Lighthouse score.
* #150 Use semantic headers for better SEO.
The test cases where failing because the test
`test_converts_Trix-formatted_attachments_with_custom_tag_name` set a
custom tag_name to `arbitrary-tag`. This test would also set the
ActionText::AttachmentGallery::ATTACHMENT_SELECTOR private constant
to `arbitrary-tag`.
Other test cases had proper ActionText::Attachment.tag_name set to
`action-text-attachment` but the constant once defined would not
reset.
This PR attempts to fix the issue by converting the
ActionText::AttachmentGallery::{ATTACHMENT_}SELECTOR to class methods
Fixes#41782
`case format when nil` is very efficient because it end up calling `NilClass === nil`
which pretty much translates to `nil.is_a?(NilClass)`.
On the other hand `format.nil?` benefit from a dedicated op code, so it's quite faster.
In this case `Integer#to_s` is much more often called without any arguments,
so it's worth optimizing for the most common case.
```ruby
class Integer
alias_method :faster_to_s, :to_s
end
require 'active_support/all'
require 'benchmark/ips'
module FasterNumericWithFormat
def faster_to_s(format = nil, options = nil)
if format.nil?
return super()
end
case format
when Integer, String
super(format)
when :phone
ActiveSupport::NumberHelper.number_to_phone(self, options || {})
when :currency
ActiveSupport::NumberHelper.number_to_currency(self, options || {})
when :percentage
ActiveSupport::NumberHelper.number_to_percentage(self, options || {})
when :delimited
ActiveSupport::NumberHelper.number_to_delimited(self, options || {})
when :rounded
ActiveSupport::NumberHelper.number_to_rounded(self, options || {})
when :human
ActiveSupport::NumberHelper.number_to_human(self, options || {})
when :human_size
ActiveSupport::NumberHelper.number_to_human_size(self, options || {})
when Symbol
super()
else
super(format)
end
end
end
Integer.prepend(FasterNumericWithFormat)
Benchmark.ips do |x|
x.report('orig no-arg') { 42.to_s }
x.report('fast no-arg') { 42.faster_to_s }
x.compare!
end
Benchmark.ips do |x|
x.report('orig :human') { 42.to_s(:human) }
x.report('fast :human') { 42.faster_to_s(:human) }
x.compare!
end
```
Ruby 2.7.2
```
Warming up --------------------------------------
orig no-arg 567.569k i/100ms
fast no-arg 692.636k i/100ms
Calculating -------------------------------------
orig no-arg 5.709M (± 1.3%) i/s - 28.946M in 5.070660s
fast no-arg 6.892M (± 0.7%) i/s - 34.632M in 5.024961s
Comparison:
fast no-arg: 6892287.7 i/s
orig no-arg: 5709450.0 i/s - 1.21x (± 0.00) slower
Warming up --------------------------------------
orig :human 575.000 i/100ms
fast :human 619.000 i/100ms
Calculating -------------------------------------
orig :human 6.176k (± 1.6%) i/s - 31.050k in 5.028656s
fast :human 6.179k (± 1.8%) i/s - 30.950k in 5.010372s
Comparison:
fast :human: 6179.1 i/s
orig :human: 6176.3 i/s - same-ish: difference falls within error
```
LogSubscriber overrides start/finish to avoid instrumenting when its
logger is nil. In order to support buffered notification events, as used
by async queries, we need to apply a similar override to
LogSubscriber#publish_event.
Calling `self.class` multiple times is not cheap.
```ruby
class A
def self.foo
end
def foo1
self.class.foo
self.class.foo
self.class.foo
self.class.foo
end
def foo2
klass = self.class
klass.foo
klass.foo
klass.foo
klass.foo
end
end
a = A.new
Benchmark.ips do |x|
x.report("foo1") { a.foo1 }
x.report("foo2") { a.foo2 }
end
```
```
Warming up --------------------------------------
foo1 341.701k i/100ms
foo2 414.000k i/100ms
Calculating -------------------------------------
foo1 3.194M (± 5.4%) i/s - 16.060M in 5.044653s
foo2 4.276M (± 3.8%) i/s - 21.528M in 5.041999s
```
Similar with #36052.
The way this test initializes `ActionDispatch::RemoteIp` has been
deprecated in #40789. This makes the test append to the existing
trusted proxy list instead of assigning a single value.
Date._iso8601 will return a hash for some values eg. '12936' but this will not contain the expected :mon and :mday keys.
Check for these keys and raise an ArgumentError if they aren't present as this is consistent with other invalid input behaviour.