Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Xml / System / Xml / ByteStack.cs / 1 / 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
- KeyConverter.cs
- PartialCachingControl.cs
- SemaphoreSecurity.cs
- XsltCompileContext.cs
- ZipIOBlockManager.cs
- FigureHelper.cs
- BitmapSource.cs
- WebResponse.cs
- ConfigXmlSignificantWhitespace.cs
- DiscoveryDocumentLinksPattern.cs
- Paragraph.cs
- Socket.cs
- BypassElementCollection.cs
- AudioSignalProblemOccurredEventArgs.cs
- PseudoWebRequest.cs
- DataTableClearEvent.cs
- KeyEventArgs.cs
- DataBinding.cs
- Menu.cs
- Assembly.cs
- SchemaAttDef.cs
- PropertyDescriptor.cs
- CacheHelper.cs
- PerformanceCounterManager.cs
- Padding.cs
- WindowsSolidBrush.cs
- MarshalByValueComponent.cs
- TextCompositionManager.cs
- TreeNodeCollection.cs
- SqlCacheDependencyDatabase.cs
- LineVisual.cs
- CanonicalFontFamilyReference.cs
- AuthorizationRuleCollection.cs
- Message.cs
- ItemCollection.cs
- SerializationInfoEnumerator.cs
- BamlBinaryWriter.cs
- XmlObjectSerializerContext.cs
- ToolboxItemSnapLineBehavior.cs
- XXXInfos.cs
- PropertyInfo.cs
- _Semaphore.cs
- SQLMoneyStorage.cs
- IntMinMaxAggregationOperator.cs
- ParallelTimeline.cs
- DataSvcMapFile.cs
- Label.cs
- CodeMemberField.cs
- SHA384Managed.cs
- DateTimeOffsetAdapter.cs
- ApplicationException.cs
- DataServiceQuery.cs
- Missing.cs
- PropertyChangedEventManager.cs
- ViewSimplifier.cs
- OleDbDataReader.cs
- AxParameterData.cs
- Atom10FeedFormatter.cs
- CheckBox.cs
- TTSEngineProxy.cs
- AppSecurityManager.cs
- DesignerSerializerAttribute.cs
- StringStorage.cs
- LongAverageAggregationOperator.cs
- _WinHttpWebProxyDataBuilder.cs
- StoreUtilities.cs
- Assert.cs
- DropDownButton.cs
- GridViewCancelEditEventArgs.cs
- ExpandedProjectionNode.cs
- SchemaTypeEmitter.cs
- Annotation.cs
- Brush.cs
- Common.cs
- PlainXmlDeserializer.cs
- UrlPath.cs
- PopupRoot.cs
- NameValueFileSectionHandler.cs
- DateTimeOffsetStorage.cs
- SqlUserDefinedAggregateAttribute.cs
- X509ChainPolicy.cs
- ConsoleKeyInfo.cs
- CredentialCache.cs
- RegexCaptureCollection.cs
- TableLayoutCellPaintEventArgs.cs
- DoubleAnimationUsingKeyFrames.cs
- BaseDataBoundControl.cs
- Literal.cs
- _OSSOCK.cs
- MULTI_QI.cs
- PropertyGridEditorPart.cs
- TextTreeUndo.cs
- DataSourceCache.cs
- InkCanvasAutomationPeer.cs
- NumberSubstitution.cs
- CustomCategoryAttribute.cs
- Compress.cs
- ErrorFormatter.cs
- ConfigXmlText.cs
- LongSumAggregationOperator.cs