Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / Utils / Util.cs / 1305376 / Util.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // Util.cs // //[....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; namespace System.Linq.Parallel { ////// Common miscellaneous utility methods used throughout the code-base. /// internal static class Util { //------------------------------------------------------------------------------------ // Simple helper that returns a constant depending on the sign of the argument. I.e. // if the argument is negative, the result is -1; if it's positive, the result is 1; // otherwise, if it's zero, the result is 0. // internal static int Sign(int x) { return x < 0 ? -1 : x == 0 ? 0 : 1; } //----------------------------------------------------------------------------------- // This is a temporary workaround for a VSWhidbey bug 601998 in the X64 JIT compiler. // Unlike the X86 JIT, null checks on value types aren't optimized away in Whidbey. // That means using the GenericComparerinfrastructure results in boxing value // types. This kills performance all over the place. This bug has been fixed in // Orcas (2.0 SP1), so once we're on the SP1 runtime, this can be removed. // internal static Comparer GetDefaultComparer () { if (typeof(TKey) == typeof(int)) { return (Comparer )(object)s_fastIntComparer; } else if (typeof(TKey) == typeof(long)) { return (Comparer )(object)s_fastLongComparer; } else if (typeof(TKey) == typeof(float)) { return (Comparer )(object)s_fastFloatComparer; } else if (typeof(TKey) == typeof(double)) { return (Comparer )(object)s_fastDoubleComparer; } else if (typeof(TKey) == typeof(DateTime)) { return (Comparer )(object)s_fastDateTimeComparer; } return Comparer .Default; } private static FastIntComparer s_fastIntComparer = new FastIntComparer(); class FastIntComparer : Comparer { public override int Compare(int x, int y) { return x.CompareTo(y); } } private static FastLongComparer s_fastLongComparer = new FastLongComparer(); class FastLongComparer : Comparer { public override int Compare(long x, long y) { return x.CompareTo(y); } } private static FastFloatComparer s_fastFloatComparer = new FastFloatComparer(); class FastFloatComparer : Comparer { public override int Compare(float x, float y) { return x.CompareTo(y); } } private static FastDoubleComparer s_fastDoubleComparer = new FastDoubleComparer(); class FastDoubleComparer : Comparer { public override int Compare(double x, double y) { return x.CompareTo(y); } } private static FastDateTimeComparer s_fastDateTimeComparer = new FastDateTimeComparer(); class FastDateTimeComparer : Comparer { public override int Compare(DateTime x, DateTime y) { return x.CompareTo(y); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // Util.cs // // [....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; namespace System.Linq.Parallel { ////// Common miscellaneous utility methods used throughout the code-base. /// internal static class Util { //------------------------------------------------------------------------------------ // Simple helper that returns a constant depending on the sign of the argument. I.e. // if the argument is negative, the result is -1; if it's positive, the result is 1; // otherwise, if it's zero, the result is 0. // internal static int Sign(int x) { return x < 0 ? -1 : x == 0 ? 0 : 1; } //----------------------------------------------------------------------------------- // This is a temporary workaround for a VSWhidbey bug 601998 in the X64 JIT compiler. // Unlike the X86 JIT, null checks on value types aren't optimized away in Whidbey. // That means using the GenericComparerinfrastructure results in boxing value // types. This kills performance all over the place. This bug has been fixed in // Orcas (2.0 SP1), so once we're on the SP1 runtime, this can be removed. // internal static Comparer GetDefaultComparer () { if (typeof(TKey) == typeof(int)) { return (Comparer )(object)s_fastIntComparer; } else if (typeof(TKey) == typeof(long)) { return (Comparer )(object)s_fastLongComparer; } else if (typeof(TKey) == typeof(float)) { return (Comparer )(object)s_fastFloatComparer; } else if (typeof(TKey) == typeof(double)) { return (Comparer )(object)s_fastDoubleComparer; } else if (typeof(TKey) == typeof(DateTime)) { return (Comparer )(object)s_fastDateTimeComparer; } return Comparer .Default; } private static FastIntComparer s_fastIntComparer = new FastIntComparer(); class FastIntComparer : Comparer { public override int Compare(int x, int y) { return x.CompareTo(y); } } private static FastLongComparer s_fastLongComparer = new FastLongComparer(); class FastLongComparer : Comparer { public override int Compare(long x, long y) { return x.CompareTo(y); } } private static FastFloatComparer s_fastFloatComparer = new FastFloatComparer(); class FastFloatComparer : Comparer { public override int Compare(float x, float y) { return x.CompareTo(y); } } private static FastDoubleComparer s_fastDoubleComparer = new FastDoubleComparer(); class FastDoubleComparer : Comparer { public override int Compare(double x, double y) { return x.CompareTo(y); } } private static FastDateTimeComparer s_fastDateTimeComparer = new FastDateTimeComparer(); class FastDateTimeComparer : Comparer { public override int Compare(DateTime x, DateTime y) { return x.CompareTo(y); } } } } // 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
- CreateUserWizardAutoFormat.cs
- DataSourceSelectArguments.cs
- BooleanFacetDescriptionElement.cs
- objectresult_tresulttype.cs
- QilPatternVisitor.cs
- Code.cs
- EntityDescriptor.cs
- RelationshipEndCollection.cs
- ScriptModule.cs
- ColumnMap.cs
- VideoDrawing.cs
- Substitution.cs
- ObsoleteAttribute.cs
- SafeHandle.cs
- UIElement.cs
- UriParserTemplates.cs
- SHA1Cng.cs
- DataServiceQueryException.cs
- Psha1DerivedKeyGenerator.cs
- MaterialGroup.cs
- RuleInfoComparer.cs
- CheckBoxFlatAdapter.cs
- URLMembershipCondition.cs
- ConfigXmlCDataSection.cs
- ValueQuery.cs
- DataGridViewUtilities.cs
- PointHitTestResult.cs
- ObfuscateAssemblyAttribute.cs
- AnonymousIdentificationModule.cs
- DriveInfo.cs
- SystemInformation.cs
- TextCompositionManager.cs
- xmlglyphRunInfo.cs
- NativeMethods.cs
- PersonalizationStateInfo.cs
- ForwardPositionQuery.cs
- COAUTHINFO.cs
- UIElement3D.cs
- XmlSchemaSet.cs
- ContextProperty.cs
- DataGridViewControlCollection.cs
- FormClosingEvent.cs
- XmlDataSourceDesigner.cs
- HandledMouseEvent.cs
- ClientUtils.cs
- XamlToRtfParser.cs
- NativeMethods.cs
- JavaScriptSerializer.cs
- SqlServices.cs
- GridViewRowEventArgs.cs
- FrameAutomationPeer.cs
- MatrixAnimationBase.cs
- CodeAssignStatement.cs
- PageBuildProvider.cs
- Span.cs
- PropertyConverter.cs
- Timer.cs
- BamlLocalizableResourceKey.cs
- EventRoute.cs
- QilStrConcatenator.cs
- NumberFormatter.cs
- PathStreamGeometryContext.cs
- MultiPageTextView.cs
- UnsafeNativeMethods.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- DataGridLinkButton.cs
- Debugger.cs
- RelationshipEndMember.cs
- ToolStripPanelRenderEventArgs.cs
- SqlClientWrapperSmiStream.cs
- WebConfigurationFileMap.cs
- RawMouseInputReport.cs
- RadioButtonStandardAdapter.cs
- DecoderFallback.cs
- OutputCacheSection.cs
- FloatUtil.cs
- FillRuleValidation.cs
- TypeLibConverter.cs
- TableLayoutPanelResizeGlyph.cs
- IgnorePropertiesAttribute.cs
- exports.cs
- ConstraintConverter.cs
- UserControlDesigner.cs
- FormViewRow.cs
- MarshalByRefObject.cs
- SqlUDTStorage.cs
- RunInstallerAttribute.cs
- HttpBrowserCapabilitiesBase.cs
- PasswordTextNavigator.cs
- FreeIndexList.cs
- Wizard.cs
- EntityDataSourceConfigureObjectContext.cs
- OracleColumn.cs
- XPathBinder.cs
- NavigateEvent.cs
- QueryOpeningEnumerator.cs
- DataGridViewAccessibleObject.cs
- HtmlControlPersistable.cs
- login.cs
- StrokeNode.cs