From 48ae36d48bba10ab1bcb8ddcb798b936095a2804 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kim=20Nguy=E1=BB=85n?= Date: Fri, 20 Apr 2012 16:01:53 +0200 Subject: [PATCH] Favor {first,next}_element calls instead of select_{descendant,following_below}, when the set of target tags is large (esp. it contains everything but attributes). --- src/l2JIT.ml | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/l2JIT.ml b/src/l2JIT.ml index c15d236..efe7854 100644 --- a/src/l2JIT.ml +++ b/src/l2JIT.ml @@ -146,6 +146,12 @@ let has_text l = Ptset.Int.mem Tag.pcdata l let rec translate_jump tree tag (jkind:Ata.jump_kind) dir s = let child, desc, sib, fol = Tree.tags tree tag in + let not_elements = + Ptset.Int.add Tag.pcdata + (Ptset.Int.add Tag.attribute + (Ptset.Int.add Tag.attribute_data + (Tree.attribute_tags tree))) + in match jkind, dir with | NIL, _ -> _nop | NODE, DIR_LEFT -> FIRST_CHILD s @@ -179,9 +185,21 @@ let rec translate_jump tree tag (jkind:Ata.jump_kind) dir s = let labels = Ptset.Int.inter l_many t in let c = Ptset.Int.cardinal labels in if c == 0 then _nop - else if c == 1 then tagged_many s (Ptset.Int.choose labels) - else if c > 5 then if has_text labels then any s else any_notext s - else select_many s labels + else + let not_t = Ptset.Int.diff l_many labels in + let () = + LOG(__ "level2-jit" 3 "Would jump for tag %s to labels %a, not relevant tags: %a" + (Tag.to_string tag) + TagSet.print (TagSet.inj_positive labels) + TagSet.print (TagSet.inj_positive not_t)) + in + if Ptset.Int.subset not_t not_elements then + if has_text labels then any s else any_notext s + else if c == 1 then tagged_many s (Ptset.Int.choose labels) + else + if c >= 5 then + if has_text labels then any s else any_notext s + else select_many s labels | CAPTURE_MANY (t), DIR_LEFT -> if Ptset.Int.is_singleton t then TAGGED_SUBTREE(s, Ptset.Int.choose t) -- 2.17.1