diff -r 000000000000 -r 818e61de6cd1 crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbolLib/CodeSeg/CodeSegDefinitionCollectionComparers.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbolLib/CodeSeg/CodeSegDefinitionCollectionComparers.cs Thu Feb 11 15:50:58 2010 +0200 @@ -0,0 +1,135 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +using System; +using System.Collections.Generic; + +namespace SymbolLib.CodeSegDef +{ + internal class CodeSegDefinitionCollectionCompareByFileName : IComparer + { + #region IComparer Members + public int Compare( object aLeft, object aRight ) + { + int ret = -1; + // + if ( aLeft == null || aRight == null ) + { + if ( aRight == null ) + { + ret = 1; + } + } + else + { + CodeSegDefinition left = (CodeSegDefinition) aLeft; + CodeSegDefinition right = (CodeSegDefinition) aRight; + // + ret = Compare( left, right ); + } + // + return ret; + } + #endregion + + #region IComparer Members + int IComparer.Compare( CodeSegDefinition aLeft, CodeSegDefinition aRight ) + { + int ret = -1; + // + if ( aLeft == null || aRight == null ) + { + if ( aRight == null ) + { + ret = 1; + } + } + else + { + ret = string.Compare( aLeft.ImageFileNameAndPath, aRight.ImageFileNameAndPath, true ); + } + // + return ret; + } + #endregion + } + + internal class CodeSegDefinitionCollectionCompareByAddress : IComparer + { + #region IComparer Members + public int Compare( object aLeft, object aRight ) + { + int ret = -1; + // + if ( aLeft == null || aRight == null ) + { + if ( aRight == null ) + { + ret = 1; + } + } + else + { + CodeSegDefinition left = (CodeSegDefinition) aLeft; + CodeSegDefinition right = (CodeSegDefinition) aRight; + // + ret = Compare( left, right ); + } + // + return ret; + } + #endregion + + #region IComparer Members + int IComparer.Compare( CodeSegDefinition aLeft, CodeSegDefinition aRight ) + { + int ret = -1; + if ( aLeft.AddressStart == aRight.AddressStart && aLeft.AddressEnd == aRight.AddressEnd ) + { + ret = 0; + } + else if ( aLeft.AddressEnd == aRight.AddressStart ) + { + System.Diagnostics.Debug.Assert( aLeft.AddressStart < aRight.AddressStart ); + System.Diagnostics.Debug.Assert( aRight.AddressEnd >= aLeft.AddressEnd ); + // + ret = -1; + } + else if ( aLeft.AddressStart == aRight.AddressEnd ) + { + System.Diagnostics.Debug.Assert( aRight.AddressStart < aLeft.AddressStart ); + System.Diagnostics.Debug.Assert( aLeft.AddressEnd >= aRight.AddressEnd ); + // + ret = 1; + } + else if ( aLeft.AddressStart > aRight.AddressEnd ) + { + System.Diagnostics.Debug.Assert( aLeft.AddressEnd > aRight.AddressEnd ); + System.Diagnostics.Debug.Assert( aLeft.AddressEnd > aRight.AddressStart ); + ret = 1; + } + else if ( aLeft.AddressEnd < aRight.AddressStart ) + { + System.Diagnostics.Debug.Assert( aLeft.AddressStart < aRight.AddressEnd ); + System.Diagnostics.Debug.Assert( aRight.AddressEnd > aLeft.AddressEnd ); + ret = -1; + } + // + return ret; + } + #endregion + } +}