Changeset 367


Ignore:
Timestamp:
Nov 2, 2007, 2:55:38 AM (17 years ago)
Author:
dai
Message:

動的型情報の生成を高速化した。
リテラル文字列の生成処理を高速化した。

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/Classes/ActiveBasic/Core/TypeInfo.ab

    r299 r367  
    99    strNamespace As String
    1010    name As String
     11    fullName As String
    1112
    1213Protected
     
    1516    'interfaces As f(^^;;;
    1617
    17     Sub TypeBaseImpl()
    18         strNamespace = ""
    19         name = ""
    20         baseType = Nothing
    21     End Sub
    22 
    23     Sub TypeBaseImpl( strNamespace As String, name As String )
     18    Sub TypeBaseImpl( strNamespace As String, name As String, fullName As String )
    2419        This.strNamespace = strNamespace
    2520        This.name = name
     21        This.fullName = fullName
    2622        This.baseType = Nothing
    2723    End Sub
    28 
    29     Sub TypeBaseImpl( strNamespace As String, name As String, baseType As System.TypeInfo )
    30         This.strNamespace = strNamespace
    31         This.name = name
    32         This.baseType = baseType
    33     End Sub
    34 
    35     /*
    36     Sub TypeBaseImpl( strNamespace As String, name As String, baseType As Type, interfaces As ... )
    37         This.strNamespace = strNamespace
    38         This.name = name
    39         This.baseType = baseType
    40         This.interfaces = interfaces
    41     End Sub
    42     */
    4324
    4425    Sub ~TypeBaseImpl()
     
    6142
    6243    Override Function FullName() As String
    63         If strNamespace.Length > 0 Then
    64             Return strNamespace + "." + name
    65         End If
    66         Return name
     44        Return fullName
    6745    End Function
    6846
     
    11795Public
    11896    Sub _System_TypeForValueType( name As String )
    119         TypeBaseImpl( "", name )
     97        TypeBaseImpl( "", name, name )
    12098    End Sub
    12199
     
    133111    numOfReference As Long
    134112
    135     Sub _System_TypeForClass( strNamespace As String, name As String, referenceOffsets As *Long, numOfReference As Long )
    136         TypeBaseImpl( strNamespace, name )
     113    Sub _System_TypeForClass( strNamespace As String, name As String, fullName As String, referenceOffsets As *Long, numOfReference As Long )
     114        TypeBaseImpl( strNamespace, name, fullName )
    137115
    138116        This.referenceOffsets = referenceOffsets
    139117        This.numOfReference = numOfReference
    140118    End Sub
    141     Sub _System_TypeForClass( strNamespace As String, name As String )
    142         TypeBaseImpl( strNamespace, name )
     119    Sub _System_TypeForClass( strNamespace As String, name As String, fullName As String )
     120        TypeBaseImpl( strNamespace, name, fullName )
    143121    End Sub
    144122    Sub ~_System_TypeForClass()
     
    173151'--------------------------------------------------------------------
    174152Class _System_TypeBase
    175     Static pTypes As *TypeBaseImpl
     153    Static types As System.Collections.Generic.Dictionary<String, TypeBaseImpl>
    176154
    177155    Static isReady = False
    178156
    179157    Static Sub Add( typeInfo As TypeBaseImpl )
    180         pTypes = realloc( pTypes, ( count + 1 ) * SizeOf(*System.TypeInfo) )
    181         pTypes[count] = typeInfo
    182         count++
     158        types.Add( typeInfo.FullName, typeInfo )
    183159    End Sub
    184160
    185161    Static Sub InitializeValueType()
     162        types = New System.Collections.Generic.Dictionary<String, TypeBaseImpl>(8192)
     163
    186164        ' 値型の追加
    187         Add( New _System_TypeForValueType( "Byte" ) )
    188         Add( New _System_TypeForValueType( "SByte" ) )
    189         Add( New _System_TypeForValueType( "Word" ) )
    190         Add( New _System_TypeForValueType( "Integer" ) )
    191         Add( New _System_TypeForValueType( "DWord" ) )
    192         Add( New _System_TypeForValueType( "Long" ) )
    193         Add( New _System_TypeForValueType( "QWord" ) )
    194         Add( New _System_TypeForValueType( "Int64" ) )
    195         Add( New _System_TypeForValueType( "Boolean" ) )
    196         Add( New _System_TypeForValueType( "Single" ) )
    197         Add( New _System_TypeForValueType( "Double" ) )
     165        Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Byte", fullName = "Byte" ] )
     166        Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "SByte", fullName = "SByte" ] )
     167        Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Word", fullName = "Word" ] )
     168        Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Integer", fullName = "Integer" ] )
     169        Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "DWord", fullName = "DWord" ] )
     170        Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Long", fullName = "Long" ] )
     171        Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "QWord", fullName = "QWord" ] )
     172        Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Int64", fullName = "Int64" ] )
     173        Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Boolean", fullName = "Boolean" ] )
     174        Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Single", fullName = "Single" ] )
     175        Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Double", fullName = "Double" ] )
    198176    End Sub
    199177
     
    202180
    203181        '例:
    204         'Add( New _System_TypeForClass( "System", "String", [__offsets...], __numOfOffsets ) )
    205         'Search( "System","String" ).SetBaseType( Search( "System","Object" ) )
    206     End Sub
    207 
    208 Public
    209     Static count As Long
     182        'Add( New _System_TypeForClass( "System", "String", "System.String", [__offsets...], __numOfOffsets ) )
     183        '...
     184    End Sub
     185    Static Sub InitializeUserTypesForBaseType()
     186        ' このメソッドの実装はコンパイラが自動生成する
     187
     188        '例:
     189        'Search( "System.String" ).SetBaseType( Search( "System.Object" ) )
     190        '...
     191    End Sub
     192
     193Public
    210194    Static Sub Initialize()
    211         pTypes = GC_malloc( 1 )
    212         count = 0
    213 
    214195        ' 値型を初期化
    215196        InitializeValueType()
    216197
    217         isReady = True
    218198        ' Class / Interface / Enum / Delegate を初期化
    219199        InitializeUserTypes()
    220200
    221         selfTypeInfo = _System_TypeBase.Search( "System", "TypeInfo" ) As System.TypeInfo
     201        isReady = True
     202
     203        ' 基底クラスを登録
     204        InitializeUserTypesForBaseType()
     205
     206        selfTypeInfo = _System_TypeBase.Search( "System.TypeInfo" ) As System.TypeInfo
    222207
    223208        _System_DebugOnly_OutputDebugString( Ex"ready dynamic meta datas!\r\n" )
     
    228213    End Sub
    229214
    230     Static Function Search( strNamespace As LPSTR, typeName As LPSTR ) As TypeBaseImpl
    231         ' TODO: 名前空間に対応する
    232 
    233         Dim i As Long
    234         For i = 0 To ELM( count )
    235             If pTypes[i].Name = typeName Then
    236                 Return pTypes[i]
    237             End If
    238         Next
    239 
    240         Return Nothing
     215    Static Function Search( fullName As String ) As TypeBaseImpl
     216        If Object.ReferenceEquals(types, Nothing) Then
     217            Return Nothing
     218        End If
     219
     220        If isReady = False Then
     221            Return Nothing
     222        End If
     223
     224        If Object.ReferenceEquals( types.Item(fullName), Nothing ) Then
     225            OutputDebugString( "TypeSearch Failed: " )
     226            OutputDebugString( fullName )
     227            OutputDebugString( Ex"\r\n" )
     228        End If
     229
     230        Return types.Item(fullName)
    241231    End Function
    242232
     
    245235    End Function
    246236
    247     Static selfTypeInfo = Nothing As System.TypeInfo
     237    Static selfTypeInfo As System.TypeInfo
    248238
    249239End Class
     
    253243End Namespace
    254244
    255 Function _System_TypeBase_Search( strNamespace As LPSTR, typeName As LPSTR ) As ActiveBasic.Core.TypeBaseImpl
    256     Return ActiveBasic.Core._System_TypeBase.Search( strNamespace, typeName )
     245Function _System_TypeBase_Search( fullName As String ) As ActiveBasic.Core.TypeBaseImpl
     246    Return ActiveBasic.Core._System_TypeBase.Search( fullName )
    257247End Function
Note: See TracChangeset for help on using the changeset viewer.