script: Introduce Element::get_attribute_string_value#45023
Conversation
|
🔨 Triggering try run (#26148094547) for Linux (WPT) |
mrobinson
left a comment
There was a problem hiding this comment.
This is really interesting. I would say it likely makes sense to generalize this a bit to allow accessing AttrValue without having to do the conversion to Attr.
| pub(crate) fn get_attribute_string_value_with_namespace( | ||
| &self, | ||
| namespace: &Namespace, | ||
| local_name: &LocalName, | ||
| ) -> Option<String> { | ||
| self.attrs | ||
| .borrow() | ||
| .iter() | ||
| .find(|a| a.local_name() == local_name && a.namespace() == namespace) | ||
| .map(|a| String::from(&**a.value())) | ||
| } |
There was a problem hiding this comment.
Would it be possible to return Option<&str>` to avoid an allocation.
There was a problem hiding this comment.
I wanted to do that, but I am not sure how to propagate the lifetime of it. Its lifetime relates to the attribute, not the self. Do you have any suggestions on how to do that?
There was a problem hiding this comment.
This is probably okay for now. Maybe I can take a look at this later.
There was a problem hiding this comment.
You likely need Ref::map to return the ref from self.attrs.borrow() to the caller.
There was a problem hiding this comment.
I made some attempts, but got stuck since the Ref is inside an AttributesBorrow. Let's merge this PR and optimize this further in subsequent cleanups.
|
Test results for linux-wpt from try job (#26148094547): Flaky unexpected result (71)
Stable unexpected results that are known to be intermittent (11)
|
|
✨ Try run (#26148094547) succeeded. |
Not all accesses to attributes require a `cx`, since most of them don't actually need the `Attr` node, but only the value contained within. Therefore, introduce a variant that directly accesses the value, to avoid materializing attribute nodes. Doing so removes the need for one of the `temp_cx` in XPath, since it only requires the attribute value and not the full node. Part of servo#45022 Signed-off-by: Tim van der Lippe <[email protected]>
ef78082 to
05253ee
Compare
Not all accesses to attributes require a
cx, since most of them don't actually need theAttrnode, but only the value contained within. Therefore, introduce a variant that directly accesses the value, to avoid materializing attribute nodes.Doing so removes the need for one of the
temp_cxin XPath, since it only requires the attribute value and not the full node.Part of #45022
Testing: WPT