From: Colin Paul Adams <colin@co...>  20040321 18:23:35

I'm puzzled by the following code fragment in this method: // if the filter is positional, try changing f[a and b] to f[a][b] to increase // the chances of finishing early. if (filterIsPositional && filter instanceof BooleanExpression && ((BooleanExpression)filter).operator == Tokenizer.AND) { BooleanExpression bf = (BooleanExpression)filter; if (isPositionalFilter(bf.operands[0]) && bf.operands[1].getItemType()==Type.BOOLEAN && !isPositionalFilter(bf.operands[1])) { FilterExpression f1 = new FilterExpression(start, bf.operands[0]); FilterExpression f2 = new FilterExpression(f1, bf.operands[1]); //System.err.println("Simplified to: "); //f2.display(10); return f2.analyze(env); } if (isPositionalFilter(bf.operands[1]) && bf.operands[1].getItemType()==Type.BOOLEAN && !isPositionalFilter(bf.operands[0])) { FilterExpression f1 = new FilterExpression(start, bf.operands[1]); FilterExpression f2 = new FilterExpression(f1, bf.operands[0]); return f2.analyze(env); } } Translating the tests into words it reads: If f is a positional filter of form "a and b" then If a is a positional filter and b is not a positional filter, but IS a BOOLEAN then rewrite Otherwise if b is a positional filter and a is not a positional filter, but B IS a BOOLEAN then rewrite ^  I'm strugling to understand this, but the fact that the logic of the two cases is not symmetrical (i.e. the same operand is testes for being a boolean expression) worries me.  Colin Paul Adams Preston Lancashire 
From: Michael Kay <mhk@mh...>  20040322 17:33:39

Nice to have someone inspecting the code so closely. I think the first test should have been written if (isPositionalFilter(bf.operands[0]) && bf.operands[0].getItemType()==Type.BOOLEAN && !isPositionalFilter(bf.operands[1])) { But in fact I think it's not dealing correctly with the case where the filter is of the form A and B where either or both of A or B are potentially numeric (a rare case but one that needs to be considered). To guard against this the new predicate should be forced to a boolean if it's not already a boolean. This code is trying to rewrite an expression such as followingsibling::*[position()=1 and name()='fred'] as followingsibling::*[1][name()='fred'] so that it can terminate the iteration early, but I think it's probably going to get obscure predicates like [1 and 2] wrong. Thanks for pointing it out. Michael Kay # Original Message # From: saxonhelpadmin@... # [mailto:saxonhelpadmin@...] On Behalf Of # Colin Paul Adams # Sent: 21 March 2004 18:22 # To: saxonhelp@... # Subject: [saxon] FilterExpression.analyze # # I'm puzzled by the following code fragment in this method: # # // if the filter is positional, try changing f[a and # b] to f[a][b] to increase # // the chances of finishing early. # # if (filterIsPositional && # filter instanceof BooleanExpression && # ((BooleanExpression)filter).operator == # Tokenizer.AND) { # BooleanExpression bf = (BooleanExpression)filter; # if (isPositionalFilter(bf.operands[0]) && # bf.operands[1].getItemType()==Type.BOOLEAN && # !isPositionalFilter(bf.operands[1])) { # FilterExpression f1 = new # FilterExpression(start, bf.operands[0]); # FilterExpression f2 = new # FilterExpression(f1, bf.operands[1]); # //System.err.println("Simplified to: "); # //f2.display(10); # return f2.analyze(env); # } # if (isPositionalFilter(bf.operands[1]) && # bf.operands[1].getItemType()==Type.BOOLEAN && # !isPositionalFilter(bf.operands[0])) { # FilterExpression f1 = new # FilterExpression(start, bf.operands[1]); # FilterExpression f2 = new # FilterExpression(f1, bf.operands[0]); # return f2.analyze(env); # } # } # # Translating the tests into words it reads: # # If f is a positional filter of form "a and b" then If a is a # positional filter and b is not a positional filter, but IS # a BOOLEAN then rewrite # # Otherwise if b is a positional filter and a is not a positional # filter, but B IS a BOOLEAN then rewrite # ^ #  # I'm strugling to understand this, but the fact that the logic # of the two cases is not symmetrical (i.e. the same operand is # testes for being a boolean expression) worries me. #  # Colin Paul Adams # Preston Lancashire # # #  # This SF.Net email is sponsored by: IBM Linux Tutorials # Free Linux tutorial presented by Daniel Robbins, President and CEO of # GenToo technologies. Learn everything from fundamentals to system # administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click # _______________________________________________ # saxonhelp mailing list # saxonhelp@... # https://lists.sourceforge.net/lists/listinfo/saxonhelp # 
From: Colin Paul Adams <colin@co...>  20040322 20:10:44

>>>>> "Michael" == Michael Kay <mhk@...> writes: Michael> Nice to have someone inspecting the code so closely. It's supposed to be one of the advantages you get from writing open source. In theory. In practise it doesn't tend to happen so much, though.  Colin Paul Adams Preston Lancashire 