crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianStructuresLib/Debug/Symbols/Symbols/InternedName.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 #define TRACK_INTERNING_STATISTICS
       
     2 /*
       
     3 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     4 * All rights reserved.
       
     5 * This component and the accompanying materials are made available
       
     6 * under the terms of "Eclipse Public License v1.0"
       
     7 * which accompanies this distribution, and is available
       
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 *
       
    10 * Initial Contributors:
       
    11 * Nokia Corporation - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 * 
       
    15 * Description:
       
    16 *
       
    17 */
       
    18 using System;
       
    19 using System.Collections;
       
    20 using System.Text;
       
    21 using System.Text.RegularExpressions;
       
    22 using System.ComponentModel;
       
    23 using SymbianUtils.Range;
       
    24 using SymbianUtils.Strings;
       
    25 using SymbianStructuresLib.Arm;
       
    26 using SymbianStructuresLib.MemoryModel;
       
    27 using SymbianStructuresLib.Debug.Symbols.Constants;
       
    28 using SymbianStructuresLib.Debug.Common.Id;
       
    29 
       
    30 namespace SymbianStructuresLib.Debug.Symbols
       
    31 {
       
    32 	internal class InternedName
       
    33     {
       
    34         #region Static constructors
       
    35         public static InternedName NewExplicit( string aText )
       
    36         {
       
    37             InternedName ret = new InternedName( aText, string.Empty );
       
    38             return ret;
       
    39         }
       
    40 
       
    41         public static InternedName New( string aText )
       
    42         {
       
    43             InternedName ret = new InternedName( aText );
       
    44             return ret;
       
    45         }
       
    46         #endregion
       
    47 
       
    48         #region Constructors
       
    49         private InternedName( string aName )
       
    50         {
       
    51             int doubleColonPos = aName.LastIndexOf( "::" );
       
    52             if ( doubleColonPos > 0 )
       
    53             {
       
    54                 iNamePart1 = aName.Substring( 0, doubleColonPos + 2 );
       
    55                 iNamePart2 = aName.Substring( doubleColonPos + 2 );
       
    56             }
       
    57             else if ( aName.Contains( "typeinfo for " ) )
       
    58             {
       
    59                 iNamePart1 = "typeinfo for ";
       
    60                 iNamePart2 = aName.Substring( 13 );
       
    61             }
       
    62             else if ( aName.Contains( "vtable for " ) )
       
    63             {
       
    64                 iNamePart1 = "vtable for ";
       
    65                 iNamePart2 = aName.Substring( 11 );
       
    66             }
       
    67             else
       
    68             {
       
    69                 iNamePart1 = aName;
       
    70                 iNamePart2 = string.Empty;
       
    71             }
       
    72 
       
    73             // Record intern stats
       
    74 #if TRACK_INTERNING_STATISTICS
       
    75             UpdateStatistics();
       
    76 #endif
       
    77 
       
    78             // Now get the interned strings
       
    79             iNamePart1 = string.Intern( iNamePart1 );
       
    80             iNamePart2 = string.Intern( iNamePart2 );
       
    81         }
       
    82 
       
    83         private InternedName( string aPart1, string aPart2 )
       
    84         {
       
    85             iNamePart1 = string.Intern( aPart1 );
       
    86             iNamePart2 = string.Intern( aPart2 );
       
    87         }
       
    88         #endregion
       
    89 
       
    90         #region API
       
    91         public static bool IsFunction( string aText )
       
    92         {
       
    93             bool ret = aText.Contains( "(" ) && aText.Contains( ")" );
       
    94             return ret;
       
    95         }
       
    96 
       
    97         public static bool IsVTable( string aText )
       
    98         {
       
    99             bool ret = StringUtils.StartsWithAny( SymbolConstants.KVTableOrTypeInfoPrefixes, aText );
       
   100             return ret;
       
   101         }
       
   102 
       
   103         public static bool IsReadOnly( string aText )
       
   104         {
       
   105             bool ret = aText.StartsWith( SymbolConstants.KPrefixReadonly );
       
   106             return ret;
       
   107         }
       
   108 
       
   109         public static bool IsSubObject( string aText )
       
   110         {
       
   111             bool ret = aText.EndsWith( SymbolConstants.KPrefixSubObject );
       
   112             return ret;
       
   113         }
       
   114 
       
   115         public void PrintStats()
       
   116         {
       
   117 #if TRACK_INTERNING_STATISTICS
       
   118 #endif
       
   119         }
       
   120         #endregion
       
   121 
       
   122         #region Internal methods
       
   123 #if TRACK_INTERNING_STATISTICS
       
   124         private void UpdateStatistics()
       
   125         {
       
   126             UpdateStatistics( iNamePart1 );
       
   127             UpdateStatistics( iNamePart2 );
       
   128         }
       
   129 
       
   130         private void UpdateStatistics( string aText )
       
   131         {
       
   132             if ( string.IsInterned( aText ) != null )
       
   133             {
       
   134                 InternStats[ 0 ].Update( aText ); 
       
   135             }
       
   136             else
       
   137             {
       
   138                 InternStats[ 1 ].Update( aText );
       
   139             }
       
   140         }
       
   141 #endif
       
   142         #endregion
       
   143 
       
   144         #region From System.Object
       
   145         public override string ToString()
       
   146         {
       
   147             return iNamePart1 + iNamePart2;
       
   148         }
       
   149         #endregion
       
   150 
       
   151         #region Internal classes
       
   152 #if TRACK_INTERNING_STATISTICS
       
   153         private class InternStatistics
       
   154         {
       
   155             public void Update( string aText )
       
   156             {
       
   157                 ++iCount;
       
   158                 iSize += (uint) ( aText.Length * 2 );
       
   159             }
       
   160             //
       
   161             private uint iCount = 0;
       
   162             private ulong iSize = 0;
       
   163         }
       
   164 #endif
       
   165         #endregion
       
   166 
       
   167         #region Data members
       
   168         private readonly string iNamePart1;
       
   169         private readonly string iNamePart2;
       
   170 
       
   171 #if TRACK_INTERNING_STATISTICS
       
   172         private static readonly InternStatistics[] InternStats = new InternStatistics[] { new InternStatistics(), new InternStatistics() };
       
   173 #endif
       
   174        #endregion
       
   175     }
       
   176 }