Skip to content
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

Use keyword arguments for performance #24519

Merged
merged 1 commit into from
Apr 13, 2016
Merged

Conversation

bogdan
Copy link
Contributor

@bogdan bogdan commented Apr 12, 2016

Following up for #24511 (comment)

r? @jeremy

result &&= options[:from] == changed_attributes[attr] if options.key?(:from)
end
result &&= to == __send__(attr) unless to == :none
result &&= from == changed_attributes[attr] unless from == :none
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically :none could be a valid to/from value. We'd need a guaranteed unique sentinel value, like OMITTED = Object.new. That starts looking pretty bad though.

Our other choice is **options, but then we lose the if options short-circuit when none are provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to imagine the case where attribute value is a symbol. Definitely not the case of AR.

@vipulnsward
Copy link
Member

@bogdan I had sent #24516, feel free to pull in the dropping of options change here.

@bogdan bogdan force-pushed the diry-keyword-args branch 2 times, most recently from 8e9fa41 to 5e3c868 Compare April 12, 2016 16:28
@bogdan
Copy link
Contributor Author

bogdan commented Apr 12, 2016

@jeremy used a more exotic symbol to describe the option omission to make impossible to randomly match to real value.

@@ -174,12 +174,10 @@ def changed_attributes
end

# Handles <tt>*_changed?</tt> for +method_missing+.
def attribute_changed?(attr, options = nil) #:nodoc:
def attribute_changed?(attr, from: :__none__, to: :__none__) # :nodoc:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a poison object here instead so that all possible user provided values are valid?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bogdan
Copy link
Contributor Author

bogdan commented Apr 12, 2016

@jeremy @sgrif you want it - you get it.

@@ -119,6 +119,9 @@ module Dirty
extend ActiveSupport::Concern
include ActiveModel::AttributeMethods

OPTION_NOT_GIVEN = Object.new
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be # :nodoc:?

@bogdan bogdan force-pushed the diry-keyword-args branch 2 times, most recently from fac9642 to c202944 Compare April 12, 2016 22:50
@sgrif
Copy link
Contributor

sgrif commented Apr 13, 2016

The failures are valid. We'll still need the !! here

@@ -189,7 +189,7 @@ def attribute_was(attr) # :nodoc:
end

# Handles <tt>*_previously_changed?</tt> for +method_missing+.
def attribute_previously_changed?(attr, options = {}) #:nodoc:
def attribute_previously_changed?(attr) #:nodoc:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the story re. changing the method signature? Is it related to this PR or just seem superfluous? Is it used/overridden/expected elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipulnsward did it in his alternative PR for some reason and recommended it to be used in mine. Sorry, I didn't think it through myself. @vipulnsward can you explain it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremy The options are not passed to, or used here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the arg was added for parity with the attribute_changed? method signature, despite being unused. It's only been present through 5.0.0 betas. Think we're good to drop it. If the method takes args later, they'll be keyword args anyway.

@jeremy jeremy merged commit e25d7a7 into rails:master Apr 13, 2016
bogdan added a commit to bogdan/rails that referenced this pull request Apr 13, 2016
sgrif added a commit that referenced this pull request Apr 13, 2016
Fixed bug introduced in #24519. Makes build green again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants