-
Notifications
You must be signed in to change notification settings - Fork 76
Deprecate accepting array as an element in XPath.match, first and each #252
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
Conversation
XPath.match, first, each accepted array as an element. This behavior is not documented, and making hard to optimize and refactor. The second argument of XPathParser#parse and XPathParser#match is also changed from nodeset to node
In this case, I made further improvements to #249, which eliminated the slowness.
How about instead of removing a feature, a deprecated message should be displayed if it is specified in an array? What do you think @kou? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK that we drop support for nodeset because we don't have enough resource to complete nodeset support.
In general, we want to keep backward compatibility as much as possible. But we can remove the feature without keeping backward compatibility because:
- It's not documented
- It doesn't work in some cases
But could you report a warning as @naitoh suggested something like:
diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb
index 5eb1e5a..a2b2ef5 100644
--- a/lib/rexml/xpath_parser.rb
+++ b/lib/rexml/xpath_parser.rb
@@ -136,11 +136,12 @@ module REXML
end
- def match(path_stack, nodeset)
- nodeset = nodeset.collect.with_index do |node, i|
- position = i + 1
- XPathNode.new(node, position: position)
+ def match(path_stack, node)
+ if node.is_a?(Array)
+ warn("REXML::XPath.XXX dropped support for nodeset...", uplevel: N)
+ node = node.first
end
+ nodeset = [XPathNode.new(node, position: 1)]
result = expr(path_stack, nodeset)
case result
when Array # nodeset
Co-authored-by: Sutou Kouhei <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks!
@tompng |
@naitoh |
Thanks! |
XPath.match
,XPath.first
,XPath.each
,XPathParser#parse
andXPathParser#match
accepted nodeset as element.This pull request changes the first parameter of these method to be an element instead of nodeset.
Passing nodeset will be deprecated.
Background
#249 will introduce a temporary cache.
But the signature
XPathParser#match(path, nodeset)
does not guarantee that all nodes in the nodeset has the same root document.So cache does not work in the code below. It's still slow.
The interface is holding our back, so I propose to drop accepting array as element.
This change is a backward incompatibility, but it just drops undocumented feature. I think only the test code was unintentionally using this feature.
XPath.match with array
XPath.match only traverse the first element of the array for some selectors.
It indicates that
XPath.match
is not designed to search inside multiple nodes/documents.