Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Xml / System / Xml / ByteStack.cs / 1305376 / ByteStack.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
//-----------------------------------------------------------------------------
using System;
namespace System.Xml {
// This stack is designed to minimize object creation for the
// objects being stored in the stack by allowing them to be
// re-used over time. It basically pushes the objects creating
// a high water mark then as Pop() is called they are not removed
// so that next time Push() is called it simply returns the last
// object that was already on the stack.
internal class ByteStack {
private byte[] stack;
private int growthRate;
private int top;
private int size;
public ByteStack(int growthRate) {
this.growthRate = growthRate;
top = 0;
stack = new byte[growthRate];
size = growthRate;
}
public void Push(byte data) {
if (size == top) {
byte[] newstack = new byte[size + growthRate];
if (top > 0) {
Buffer.BlockCopy(stack, 0, newstack, 0, top);
}
stack = newstack;
size += growthRate;
}
stack[top++] = data;
}
public byte Pop() {
if (top > 0) {
return stack[--top];
} else {
return 0;
}
}
public byte Peek() {
if (top > 0) {
return stack[top - 1];
} else {
return 0;
}
}
public int Length {
get {
return top;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
//-----------------------------------------------------------------------------
using System;
namespace System.Xml {
// This stack is designed to minimize object creation for the
// objects being stored in the stack by allowing them to be
// re-used over time. It basically pushes the objects creating
// a high water mark then as Pop() is called they are not removed
// so that next time Push() is called it simply returns the last
// object that was already on the stack.
internal class ByteStack {
private byte[] stack;
private int growthRate;
private int top;
private int size;
public ByteStack(int growthRate) {
this.growthRate = growthRate;
top = 0;
stack = new byte[growthRate];
size = growthRate;
}
public void Push(byte data) {
if (size == top) {
byte[] newstack = new byte[size + growthRate];
if (top > 0) {
Buffer.BlockCopy(stack, 0, newstack, 0, top);
}
stack = newstack;
size += growthRate;
}
stack[top++] = data;
}
public byte Pop() {
if (top > 0) {
return stack[--top];
} else {
return 0;
}
}
public byte Peek() {
if (top > 0) {
return stack[top - 1];
} else {
return 0;
}
}
public int Length {
get {
return top;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AttributeEmitter.cs
- DSASignatureFormatter.cs
- DiagnosticTraceSource.cs
- MatcherBuilder.cs
- FreezableDefaultValueFactory.cs
- DataTableMappingCollection.cs
- MethodBuilderInstantiation.cs
- VolatileEnlistmentState.cs
- CallContext.cs
- ActivityDesignerAccessibleObject.cs
- ColumnMapVisitor.cs
- PostBackTrigger.cs
- UnsafeNativeMethods.cs
- ExpressionBuilder.cs
- LinkedList.cs
- ExcludeFromCodeCoverageAttribute.cs
- SizeConverter.cs
- ProcessInfo.cs
- AnnotationObservableCollection.cs
- ToolboxItemWrapper.cs
- EtwTrace.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- DSACryptoServiceProvider.cs
- basevalidator.cs
- SplineKeyFrames.cs
- GenericEnumConverter.cs
- Helpers.cs
- EpmContentDeSerializer.cs
- BitmapEffectCollection.cs
- ChannelProtectionRequirements.cs
- ObjectCloneHelper.cs
- SspiHelper.cs
- ServiceModelActivationSectionGroup.cs
- ISessionStateStore.cs
- _CookieModule.cs
- SerializerWriterEventHandlers.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- HyperLink.cs
- CollectionChangeEventArgs.cs
- DriveNotFoundException.cs
- NavigatingCancelEventArgs.cs
- CodeIterationStatement.cs
- DataGridViewComboBoxColumn.cs
- ToolStripPanelSelectionGlyph.cs
- CapabilitiesState.cs
- HotSpot.cs
- NumericUpDownAcceleration.cs
- XPathScanner.cs
- PersianCalendar.cs
- ComboBoxItem.cs
- QuarticEase.cs
- DocumentStatusResources.cs
- BooleanKeyFrameCollection.cs
- UInt64Storage.cs
- ScriptingSectionGroup.cs
- WebPartZoneCollection.cs
- DiscoveryDocumentReference.cs
- DataGridViewColumnCollectionEditor.cs
- TransformerConfigurationWizardBase.cs
- CompilerCollection.cs
- GeneratedView.cs
- AdRotator.cs
- TimeoutException.cs
- Quaternion.cs
- StylusDownEventArgs.cs
- KeyConstraint.cs
- TextContainer.cs
- PersonalizationStateInfoCollection.cs
- CodeAccessPermission.cs
- Transform.cs
- PeerHopCountAttribute.cs
- FileRecordSequenceHelper.cs
- AsyncWaitHandle.cs
- XmlSchemaAppInfo.cs
- BindingCollection.cs
- InputLanguage.cs
- CodeEventReferenceExpression.cs
- TrustManager.cs
- FontUnitConverter.cs
- KeyTimeConverter.cs
- CodeArrayIndexerExpression.cs
- ProfileService.cs
- DataBindingCollectionConverter.cs
- HttpCapabilitiesEvaluator.cs
- DockPanel.cs
- Input.cs
- RepeatBehavior.cs
- FrameworkEventSource.cs
- Base64Encoder.cs
- DrawListViewColumnHeaderEventArgs.cs
- ConfigurationManager.cs
- AdornerHitTestResult.cs
- ClientConvert.cs
- BrowserCapabilitiesCodeGenerator.cs
- XhtmlBasicValidatorAdapter.cs
- GradientStopCollection.cs
- X509SecurityTokenProvider.cs
- XsltSettings.cs
- AddInControllerImpl.cs
- Int64Animation.cs