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
- FileStream.cs
- GlobalEventManager.cs
- HtmlTextArea.cs
- SocketInformation.cs
- UpdateProgress.cs
- SystemIPv6InterfaceProperties.cs
- Delay.cs
- SqlInternalConnection.cs
- CuspData.cs
- Int16.cs
- DataGridTableCollection.cs
- AbstractExpressions.cs
- XmlWriter.cs
- CustomErrorsSection.cs
- ByteConverter.cs
- ListItemParagraph.cs
- DataGridView.cs
- InkCanvasSelectionAdorner.cs
- DodSequenceMerge.cs
- RuntimeConfig.cs
- TemplateControlParser.cs
- AutomationPatternInfo.cs
- _AutoWebProxyScriptWrapper.cs
- WebSysDescriptionAttribute.cs
- EventHandlersStore.cs
- AuthorizationRule.cs
- SafeUserTokenHandle.cs
- Directory.cs
- Descriptor.cs
- DiscoveryExceptionDictionary.cs
- CompositeFontInfo.cs
- IndentedTextWriter.cs
- ViewSimplifier.cs
- FlowLayoutSettings.cs
- LOSFormatter.cs
- FixedStringLookup.cs
- StyleBamlTreeBuilder.cs
- SqlDelegatedTransaction.cs
- SingleSelectRootGridEntry.cs
- TreeViewAutomationPeer.cs
- ReaderContextStackData.cs
- SchemaImporterExtensionElement.cs
- FileDialog.cs
- _ContextAwareResult.cs
- TableRowCollection.cs
- DesignTimeVisibleAttribute.cs
- BindingExpressionUncommonField.cs
- MenuItemCollection.cs
- Point.cs
- diagnosticsswitches.cs
- RoleManagerSection.cs
- CancelRequestedQuery.cs
- InfocardExtendedInformationCollection.cs
- RequestCacheValidator.cs
- FixedSOMContainer.cs
- HashCodeCombiner.cs
- DecimalFormatter.cs
- EllipticalNodeOperations.cs
- DatePickerAutomationPeer.cs
- GcSettings.cs
- UseLicense.cs
- PassportIdentity.cs
- RemoteWebConfigurationHostServer.cs
- RuleValidation.cs
- OdbcConnectionOpen.cs
- DataGridItemCollection.cs
- ProviderUtil.cs
- MappingItemCollection.cs
- DesignerValidationSummaryAdapter.cs
- BroadcastEventHelper.cs
- RegistrationServices.cs
- MetadataArtifactLoaderComposite.cs
- MembershipUser.cs
- OutputCacheModule.cs
- WebControlsSection.cs
- XmlDocumentType.cs
- ActivityDesignerAccessibleObject.cs
- IntegerValidator.cs
- Int32Storage.cs
- PrinterSettings.cs
- SmtpDigestAuthenticationModule.cs
- DataGridViewRowCancelEventArgs.cs
- SmiRecordBuffer.cs
- FolderBrowserDialogDesigner.cs
- KeyToListMap.cs
- QilGeneratorEnv.cs
- Facet.cs
- DiscoveryDocumentSearchPattern.cs
- RectAnimationClockResource.cs
- DesignerDeviceConfig.cs
- CollectionViewGroupRoot.cs
- ProcessHostMapPath.cs
- InputBuffer.cs
- FileNotFoundException.cs
- Dynamic.cs
- TextWriter.cs
- HtmlTableCellCollection.cs
- WebBrowserNavigatingEventHandler.cs
- UnlockCardRequest.cs
- ExpandButtonVisibilityConverter.cs