File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 22using System . Collections . Generic ;
33using System . Diagnostics ;
44using System . IO ;
5+ using System . Linq ;
6+ using KScr . Core . Bytecode ;
7+ using KScr . Core . Std ;
58
69namespace KScr . Core . Util ;
710
@@ -10,6 +13,20 @@ public sealed class StringCache
1013 public const string FileName = "strings" + RuntimeBase . BinaryFileExt ;
1114
1215 public static readonly byte [ ] NewLineBytes = RuntimeBase . Encoding . GetBytes ( "\n " ) ;
16+
17+ public static IEnumerable < string > CommonStrings => new [ ] { Method . ConstructorName , Method . StaticInitializerName }
18+ . Concat ( GetAllClasses ( Class . LibRootPackage )
19+ . SelectMany ( cls => new [ ] { cls . CanonicalName , cls . FullDetailedName } ) ) ;
20+
21+ private static IEnumerable < Class > GetAllClasses ( IPackageMember mem )
22+ {
23+ if ( mem is Package pkg )
24+ return pkg . PackageMembers . Values . SelectMany ( GetAllClasses ) ;
25+ if ( mem is Class cls )
26+ return new [ ] { cls } ;
27+ throw new System . Exception ( "invalid state" ) ;
28+ }
29+
1330 private readonly IList < string > _strings = new List < string > ( ) ;
1431 private int _index = - 1 ;
1532
@@ -19,6 +36,8 @@ public int this[string str]
1936 {
2037 if ( str == null )
2138 throw new NullReferenceException ( ) ;
39+ if ( CommonStrings . Contains ( str ) )
40+ ; // todo Do not include common strings in every string cache
2241 if ( _strings . IndexOf ( str ) is var i && i != - 1 )
2342 return i ;
2443 var id = ++ _index ;
You can’t perform that action at this time.
0 commit comments