Exemplo n.º 1
0
        public override bool GetOptimized(out Path optimizedPath)
        {
            UnionPath optimizedComponents = new UnionPath(Schema);
            bool      componentsOptimized = false;

            foreach (Path componentPath in ComponentPaths)
            {
                Path optimizedComponent;
                componentsOptimized |= componentPath.GetOptimized(out optimizedComponent);
                optimizedComponents.ComponentPaths.Add(optimizedComponent);
            }

            if (optimizedComponents.ComponentPaths.Count == 1)
            {
                optimizedPath = optimizedComponents.ComponentPaths[0];
                return(true);
            }

            // small expression optimization: (###/X | ###/descendant:X) is combined to (###/descendant:X)
            if (optimizedComponents.ComponentPaths.Count > 0 && optimizedComponents.ComponentPaths.TransitiveTrue(CanBeJoinedInSteps))
            {
                optimizedPath = JoinInSteps(optimizedComponents);
                return(true);
            }

            if (componentsOptimized)
            {
                optimizedPath = optimizedComponents;
                return(true);
            }

            optimizedPath = this;
            return(false);
        }
Exemplo n.º 2
0
        private Path JoinInSteps(UnionPath optimizedComponents)
        {
            SimplePath joined = new SimplePath(Schema);

            for (int i = 0; i < ((SimplePath)optimizedComponents.ComponentPaths.First()).Steps.Count; i++)
            {
                if (optimizedComponents.ComponentPaths.Select(path => ((SimplePath)path).Steps[i]).TransitiveTrue((s1, s2) => s1 == s2))
                {
                    // ale are equal, so take first one
                    Step imageStep = ((SimplePath)optimizedComponents.ComponentPaths.First()).Steps[i];
                    joined.AddStep(imageStep.DeepCopy());
                }
                else
                {
                    Step imageStep = ((SimplePath)optimizedComponents.ComponentPaths.First()).Steps[i];
                    // they must be joined
                    Step newStep = new Step()
                    {
                        Axis = Axis.descendant, NodeTest = imageStep.NodeTest
                    };
                    joined.AddStep(newStep);
                }
            }

            return(joined);
        }
Exemplo n.º 3
0
        public override Path DeepCopy()
        {
            UnionPath copy = new UnionPath(Schema);

            base.FillCopy(copy);
            foreach (Path componentPath in ComponentPaths)
            {
                copy.ComponentPaths.Add(componentPath.DeepCopy());
            }
            return(copy);
        }