-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Allow to access a HashMap of OwnAttributes instead of Vec<OwnedAttribute> #143
Comments
That's because I wanted to make reading and writing events as close as possible, and for reading events to be cheaply convertible to writing events. Also, doing exactly what you have written is not possible, because the name of an attribute is From the performance point of view of the collections themselves, I sincerely doubt that it really matters whether it is a linear As for syntax for accessing elements by the name, using iterator methods doesn't seem to be a great detriment to me: if let Some(attr) = attributes.iter().find(|a| a.name.local_name == "something") {
..
} This also allows querying by the namespace, when it is important, using the same syntax. |
Hi netvl, I was not referring to any perf issue on using But as you said, the developer can add some helper |
As I said, the problem is that attributes cannot be named by strings, they have to be named by the structural names, because attribute names are qualified. Therefore, there just cannot be a
which not only is longer, but also requires an allocation for each access. That being said, I probably could write a wrapper around struct OwnedAttributes(Vec<OwnedAttribute>);
impl OwnedAttributes {
fn get<'a>(&'a self, name: Name) -> Option<&'a OwnedAttribute> {
self.0.iter().find(|attr| attr.name.borrow() == name)
}
} which then could be used as StartElement { attributes, .. } => {
if let Some(attr) = attributes.get(Name::local("whatever")) {
...
}
} This is probably a good idea, I may add something like this in future versions. Thanks! |
Yes, it will probably minimize some match arms. Thanks for taking this into account ! |
I'll keep this open until the feature is implemented. |
Hi,
In lots of languages (Python, Ruby,...), it's easy to query an xml element attribute by giving its name, using a dict (in Python) or a hash (in Ruby) to hold all element attributes.
Why not using a
here ?
The text was updated successfully, but these errors were encountered: