@@ -18,7 +18,7 @@ namespace Shared.Services;
1818
1919public static class CSharpEval
2020{
21- static ConcurrentDictionary < string , dynamic > scripts = new ( ) ;
21+ static ConcurrentDictionary < Fnv1aHash , dynamic > scripts = new ( ) ;
2222
2323 #region Execute<T>
2424 public static T Execute < T > ( string cs , object model , ScriptOptions options = null )
@@ -28,7 +28,7 @@ public static T Execute<T>(string cs, object model, ScriptOptions options = null
2828
2929 public static Task < T > ExecuteAsync < T > ( string cs , object model , ScriptOptions options = null )
3030 {
31- var entry = scripts . GetOrAdd ( CrypTo . md5 ( cs ) , _ =>
31+ var entry = scripts . GetOrAdd ( Fnv1a . Hash ( cs ) , _ =>
3232 {
3333 if ( options == null )
3434 options = ScriptOptions . Default ;
@@ -60,7 +60,7 @@ public static T BaseExecute<T>(string cs, object model, ScriptOptions options =
6060
6161 public static Task < T > BaseExecuteAsync < T > ( string cs , object model , ScriptOptions options = null , InteractiveAssemblyLoader loader = null )
6262 {
63- var entry = scripts . GetOrAdd ( CrypTo . md5 ( cs ) , _ =>
63+ var entry = scripts . GetOrAdd ( Fnv1a . Hash ( cs ) , _ =>
6464 {
6565 return CSharpScript . Create < T > (
6666 cs ,
@@ -82,7 +82,7 @@ public static void Execute(string cs, object model, ScriptOptions options = null
8282
8383 public static Task ExecuteAsync ( string cs , object model , ScriptOptions options = null )
8484 {
85- var entry = scripts . GetOrAdd ( CrypTo . md5 ( cs ) , _ =>
85+ var entry = scripts . GetOrAdd ( Fnv1a . Hash ( cs ) , _ =>
8686 {
8787 if ( options == null )
8888 options = ScriptOptions . Default ;
@@ -113,15 +113,16 @@ public static Task ExecuteAsync(string cs, object model, ScriptOptions options =
113113 static readonly object lockCompilationObj = new ( ) ;
114114
115115 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
116- public static ( Assembly assembly , AssemblyLoadContext alc , string path ) Compilation ( RootModule mod )
116+ public static ( Fnv1aHash sumhash , Assembly assembly , AssemblyLoadContext alc , string path ) Compilation ( RootModule mod )
117117 {
118118 lock ( lockCompilationObj )
119119 {
120120 string path = mod . path ;
121121
122122 if ( Directory . Exists ( path ) )
123123 {
124- var sumhash = new StringBuilder ( vshared ) ;
124+ var sumhash = Fnv1a . Empty ;
125+ Fnv1a . Append ( ref sumhash , vshared ) ;
125126
126127 #region syntaxTree
127128 var syntaxTree = new List < SyntaxTree > ( ) ;
@@ -178,7 +179,7 @@ public static (Assembly assembly, AssemblyLoadContext alc, string path) Compilat
178179 syntaxTree . Add ( CSharpSyntaxTree . ParseText ( sourceText , parseOptions , csfile ) ) ;
179180
180181 var checksum = sourceText . GetChecksum ( ) ;
181- sumhash . Append ( Convert . ToHexString ( checksum . ToArray ( ) ) ) ;
182+ Fnv1a . Append ( ref sumhash , checksum ) ;
182183 }
183184 }
184185 #endregion
@@ -230,15 +231,15 @@ public static (Assembly assembly, AssemblyLoadContext alc, string path) Compilat
230231 #endregion
231232
232233 #region cache dll
233- string cachePath = Path . Combine ( "cache" , "module" , $ "{ CrypTo . md5 ( sumhash ) } .dll") ;
234+ string cachePath = Path . Combine ( "cache" , "module" , $ "{ Fnv1a . Base64Url ( sumhash ) } .dll") ;
234235
235236 if ( File . Exists ( cachePath ) )
236237 {
237238 using ( var fs = File . OpenRead ( cachePath ) )
238239 {
239240 var alc = new AssemblyLoadContext ( mod . name , isCollectible : true ) ;
240241 var assembly = alc . LoadFromStream ( fs ) ;
241- return ( assembly , alc , path ) ;
242+ return ( sumhash , assembly , alc , path ) ;
242243 }
243244 }
244245 #endregion
@@ -261,7 +262,7 @@ public static (Assembly assembly, AssemblyLoadContext alc, string path) Compilat
261262 var alc = new AssemblyLoadContext ( mod . name , isCollectible : true ) ;
262263 var assembly = alc . LoadFromStream ( ms ) ;
263264
264- return ( assembly , alc , path ) ;
265+ return ( sumhash , assembly , alc , path ) ;
265266 }
266267 else
267268 {
@@ -274,7 +275,6 @@ public static (Assembly assembly, AssemblyLoadContext alc, string path) Compilat
274275 Console . WriteLine ( "\n " ) ;
275276 }
276277 }
277-
278278 }
279279
280280 return default ;
0 commit comments