-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Add new Performance/StringBytesize
cop
#474
Add new Performance/StringBytesize
cop
#474
Conversation
15a940b
to
896ba88
Compare
Performance#StringBytesize
copPerformance/StringBytesize
cop
a29b6dd
to
24e33c5
Compare
I understand the reasoning, but in Rails, replacing |
Yes, that's an issue. But isn't |
Any thoughts? @koic @dvandersluis I completely understand that we should avoid false positives (if possible), but in this particular case I believe both true and false positives are quite rate; at the same time unnecessary array allocations are painful in case of huge strings. I was inspired by code like this class BytesizeValidator < ActiveModel::Validations::LengthValidator
def validate_each(record, attribute, value)
super(record, attribute, value&.bytes)
end
end which was fixed by me to class BytesizeValidator < ActiveModel::Validations::LengthValidator
def validate_each(record, attribute, value)
super(record, attribute, value&.dup&.force_encoding(Encoding::BINARY))
end
end to reduce memory consumption |
I don't think It'd be good to have a reference and/or benchmarks for this performance suggestion. Your example doesn't actually make a good case for changing
I wouldn't change this to only check for |
@dvandersluis's opinion looks good. @viralpraxis Can you proceed with this? |
@koic I agree with @dvandersluis too. I will apply the necessary changes. |
24e33c5
to
d3637be
Compare
Thanks! |
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.