Fastest way to check ancestors using XPath and libxml2

I'm working on a little reading app that processes HTML documents using `libxml2`. While processing an HTML tree, I check every `text()` node for its ancestors to choose a proper style. For headers I'm using the following of query to see whether a node is header or not: boolean(ancestor::*[ self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6]) With a 5 MB book, it takes 1.1 seconds to pass. Together with two additional queries for emphasis and code styles (with larger set of node names), it adds up to 4.4 seconds. According to Apple's Instruments, the bottleneck line is: xmlXPathObject *object = xmlXPathNodeEval(node, query, context); I cache `context` to speed things up. Is there anything else I could do to make it faster?

以上就是Fastest way to check ancestors using XPath and libxml2的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏