Is finding Elements by a custom attribute efficient?
I开发者_如何学JAVA'm wondering whether a select statement like this would be efficient:
elements = document.body().select("[data-custom-attr=blahblah]");
Does JSoup create a Map for all element attributes and values so that it can look them up efficiently, or would this involve a traversal of the entire document?
Yes, attributes appear to be stored in a LinkedHashMap
as of v1.7.2.
org.jsoup.nodes.Attributes:
line 20: private LinkedHashMap<String, Attribute> attributes = null;
line 21: // linked hash map to preserve insertion order.
line 22: // null be default as so many elements have no attributes -- saves a good chunk of memory
I'd be remiss if I didn't tell you a good API is supposed to abstract implementation details away from the programmer. A detail like this isn't supposed to be something most developers are concerned with. Of course, no harm done if it's just for curiosity's sake.
精彩评论