Skip to content

Commit 4c85530

Browse files
committed
Fix safe performance offenses
- Performance/CompareWithBlock - Performance/ConstantRegexp - Performance/RedundantSplitRegexpArgument - Performance/StringReplacement
1 parent 8b1f1cc commit 4c85530

File tree

5 files changed

+7
-33
lines changed

5 files changed

+7
-33
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/inline_svg/cached_asset_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initialize(paths: [], filters: [])
1818
@paths = Array(paths).compact.map { |p| Pathname.new(p) }
1919
@filters = Array(filters).map { |f| Regexp.new(f) }
2020
@assets = @paths.reduce({}) { |assets, p| assets.merge(read_assets(assets, p)) }
21-
@sorted_asset_keys = assets.keys.sort { |a, b| a.size <=> b.size }
21+
@sorted_asset_keys = assets.keys.sort_by(&:size)
2222
end
2323

2424
# Public: Finds the named asset and returns the contents as a string.

lib/inline_svg/transform_pipeline/transformations/data_attributes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def with_valid_hash_from(hash)
1515
end
1616

1717
def dasherize(string)
18-
string.to_s.gsub(/_/, "-")
18+
string.to_s.tr('_', "-")
1919
end
2020
end
2121
end

lib/inline_svg/transform_pipeline/transformations/size.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ def transform(doc)
88
end
99

1010
def width_of(value)
11-
value.split(/\*/).map(&:strip)[0]
11+
value.split("*").map(&:strip)[0]
1212
end
1313

1414
def height_of(value)
15-
value.split(/\*/).map(&:strip)[1] || width_of(value)
15+
value.split("*").map(&:strip)[1] || width_of(value)
1616
end
1717
end
1818
end

spec/inline_svg_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ def self.named(filename); end
104104
InlineSvg.configure do |config|
105105
config.add_custom_transformation(attribute: :irrelevant, transform: MyInvalidCustomTransformKlass)
106106
end
107-
end.to raise_error(InlineSvg::Configuration::Invalid, /#{MyInvalidCustomTransformKlass} should implement the .create_with_value and #transform methods/)
107+
end.to raise_error(InlineSvg::Configuration::Invalid, /#{MyInvalidCustomTransformKlass} should implement the .create_with_value and #transform methods/o)
108108
end
109109

110110
it "rejects transformations that does not implement #transform" do
111111
expect do
112112
InlineSvg.configure do |config|
113113
config.add_custom_transformation(attribute: :irrelevant, transform: MyInvalidCustomTransformInstance)
114114
end
115-
end.to raise_error(InlineSvg::Configuration::Invalid, /#{MyInvalidCustomTransformInstance} should implement the .create_with_value and #transform methods/)
115+
end.to raise_error(InlineSvg::Configuration::Invalid, /#{MyInvalidCustomTransformInstance} should implement the .create_with_value and #transform methods/o)
116116
end
117117

118118
it "rejects transformations that are not classes" do

0 commit comments

Comments
 (0)