1 //------------------------------------------------------------------------------
2 // <copyright file="XmlNavigatorStack.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
9 using System.Xml.XPath;
10 using System.Diagnostics;
12 namespace System.Xml.Xsl.Runtime {
15 /// A dynamic stack of IXmlNavigators.
17 internal struct XmlNavigatorStack {
18 private XPathNavigator[] stkNav; // Stack of XPathNavigators
19 private int sp; // Stack pointer (size of stack)
22 private const int InitialStackSize = 2;
24 private const int InitialStackSize = 8;
28 /// Push a navigator onto the stack
30 public void Push(XPathNavigator nav) {
31 if (this.stkNav == null)
33 this.stkNav = new XPathNavigator[InitialStackSize];
37 if (this.sp >= this.stkNav.Length)
40 XPathNavigator[] stkOld = this.stkNav;
41 this.stkNav = new XPathNavigator[2 * this.sp];
42 Array.Copy(stkOld, this.stkNav, this.sp);
46 this.stkNav[this.sp++] = nav;
50 /// Pop the topmost navigator and return it
52 public XPathNavigator Pop() {
53 Debug.Assert(!IsEmpty);
54 return this.stkNav[--this.sp];
58 /// Returns the navigator at the top of the stack without adjusting the stack pointer
60 public XPathNavigator Peek() {
61 Debug.Assert(!IsEmpty);
62 return this.stkNav[this.sp - 1];
66 /// Remove all navigators from the stack
73 /// Returns true if there are no navigators in the stack
76 get { return this.sp == 0; }