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
- DirectoryNotFoundException.cs
- OutputScopeManager.cs
- MatrixTransform.cs
- LogAppendAsyncResult.cs
- XmlnsDefinitionAttribute.cs
- CryptoKeySecurity.cs
- Debugger.cs
- CacheForPrimitiveTypes.cs
- CompiledXpathExpr.cs
- MetadataWorkspace.cs
- _PooledStream.cs
- ZipIOExtraField.cs
- GenerateScriptTypeAttribute.cs
- ChangePassword.cs
- GroupBox.cs
- FusionWrap.cs
- ButtonDesigner.cs
- InnerItemCollectionView.cs
- CustomError.cs
- SiteMapPathDesigner.cs
- JapaneseCalendar.cs
- Part.cs
- _BasicClient.cs
- LinkUtilities.cs
- XmlCharCheckingWriter.cs
- ListenDesigner.cs
- BrowserCapabilitiesCodeGenerator.cs
- ExpressionPrinter.cs
- IProvider.cs
- PageCatalogPart.cs
- ChannelCacheDefaults.cs
- KeyValuePair.cs
- Journaling.cs
- FillRuleValidation.cs
- ResourcePermissionBaseEntry.cs
- SkewTransform.cs
- ResourceReferenceExpressionConverter.cs
- XmlText.cs
- Menu.cs
- PageWrapper.cs
- counter.cs
- XsltInput.cs
- TrustLevelCollection.cs
- FontFamilyValueSerializer.cs
- Model3D.cs
- UpdateTranslator.cs
- MsmqMessage.cs
- StrokeNodeOperations.cs
- MergeExecutor.cs
- ColorConverter.cs
- WrappedReader.cs
- SimpleTextLine.cs
- MenuCommand.cs
- FormClosedEvent.cs
- SelectionWordBreaker.cs
- ListBoxItemWrapperAutomationPeer.cs
- StackBuilderSink.cs
- Module.cs
- TimeSpan.cs
- TrackBarDesigner.cs
- Perspective.cs
- CompilationSection.cs
- StateManagedCollection.cs
- TypeProvider.cs
- HttpGetProtocolReflector.cs
- XmlCollation.cs
- BooleanAnimationBase.cs
- FormViewRow.cs
- NativeMethods.cs
- BCLDebug.cs
- XmlSchemaObjectCollection.cs
- XmlWhitespace.cs
- ConsoleEntryPoint.cs
- DateBoldEvent.cs
- ConfigXmlWhitespace.cs
- MSHTMLHost.cs
- TraceUtility.cs
- LiteralDesigner.cs
- UnicastIPAddressInformationCollection.cs
- TabletDevice.cs
- WebBodyFormatMessageProperty.cs
- SqlParameterizer.cs
- ProtocolsConfigurationHandler.cs
- SqlFormatter.cs
- ContentPlaceHolder.cs
- XNodeValidator.cs
- StateMachine.cs
- SafeFindHandle.cs
- GridViewRowPresenterBase.cs
- SchemaNamespaceManager.cs
- ProcessThreadCollection.cs
- ObjectComplexPropertyMapping.cs
- XmlSchemaAttributeGroupRef.cs
- CalloutQueueItem.cs
- EventLogLink.cs
- DeobfuscatingStream.cs
- ClientScriptManager.cs
- WindowsToolbar.cs
- BooleanFacetDescriptionElement.cs
- OutputCacheProfileCollection.cs