Apply behaviour change fix from upstream for previous XPath change.

BUG=58731
TEST=NONE

Review URL: http://codereview.chromium.org/4027006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63572 0039d316-1c4b-4281-b951-d872f2087c98
xmlXPathRewriteDOSExpression(xmlXPathCompExprPtr comp, xmlXPathStepOpPtr op)
{
    /*
    * Try to rewrite "descendant-or-self::node()/foo" to an optimized
    * internal representation.
    */
    if (op->ch1 != -1) {
	if ((op->op == XPATH_OP_COLLECT /* 11 */) &&
	    ((xmlXPathAxisVal) op->value == AXIS_CHILD /* 4 */) &&
	    ((xmlXPathTestVal) op->value2 == NODE_TEST_NAME /* 5 */) &&
	    ((xmlXPathTypeVal) op->value3 == NODE_TYPE_NODE /* 0 */))
	{
	    /*
	    * This is a "child::foo"
	    */
	    xmlXPathStepOpPtr prevop = &comp->steps[op->ch1];

	    if ((prevop->op == XPATH_OP_COLLECT /* 11 */) &&
		(prevop->ch1 != -1) &&
		((xmlXPathAxisVal) prevop->value ==
		    AXIS_DESCENDANT_OR_SELF) &&
		(prevop->ch2 == -1) &&
		((xmlXPathTestVal) prevop->value2 == NODE_TEST_TYPE) &&
		((xmlXPathTypeVal) prevop->value3 == NODE_TYPE_NODE) &&
		(comp->steps[prevop->ch1].op == XPATH_OP_ROOT))
	    {
		/*
		* This is a "/descendant-or-self::node()" without predicates.
		* Eliminate it.
		*/
		op->ch1 = prevop->ch1;
		op->rewriteType = XP_REWRITE_DOS_CHILD_ELEM;
	    }
	}
	if (op->ch1 != -1)
	    xmlXPathRewriteDOSExpression(comp, &comp->steps[op->ch1]);
    }
    if (op->ch2 != -1)
	xmlXPathRewriteDOSExpression(comp, &comp->steps[op->ch2]);
}

xmlXPathRewriteDOSExpression(xmlXPathCompExprPtr comp, xmlXPathStepOpPtr op)
{
    /*
    * Try to rewrite "descendant-or-self::node()/foo" to an optimized
    * internal representation.
    */
    if (op->ch1 != -1) {
	if ((op->op == XPATH_OP_COLLECT /* 11 */) &&
	    ((xmlXPathAxisVal) op->value == AXIS_CHILD /* 4 */) &&
	    ((xmlXPathTestVal) op->value2 == NODE_TEST_NAME /* 5 */) &&
	    ((xmlXPathTypeVal) op->value3 == NODE_TYPE_NODE /* 0 */))
	{
	    /*
	    * This is a "child::foo"
	    */
	    xmlXPathStepOpPtr prevop = &comp->steps[op->ch1];

	    if ((prevop->op == XPATH_OP_COLLECT /* 11 */) &&
		(prevop->ch1 != -1) &&
		((xmlXPathAxisVal) prevop->value ==
		    AXIS_DESCENDANT_OR_SELF) &&
		(prevop->ch2 == -1) &&
		((xmlXPathTestVal) prevop->value2 == NODE_TEST_TYPE) &&
		((xmlXPathTypeVal) prevop->value3 == NODE_TYPE_NODE) &&
		(comp->steps[prevop->ch1].op == XPATH_OP_ROOT))
	    {
		/*
		* This is a "/descendant-or-self::node()" without predicates.
		* Eliminate it.
		*/
		op->ch1 = prevop->ch1;
		op->rewriteType = XP_REWRITE_DOS_CHILD_ELEM;
	    }
	}
	if (op->ch1 != -1)
	    xmlXPathRewriteDOSExpression(comp, &comp->steps[op->ch1]);
    }
    if (op->ch2 != -1)
	xmlXPathRewriteDOSExpression(comp, &comp->steps[op->ch2]);
}
