]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/MMap.scl
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / MMap.scl
index 18e5866c080c05d35a6598c16e5382b63baa1a3f..0f050ca7695d724b3f938a75c8fd71c2837aa2b6 100644 (file)
@@ -35,6 +35,15 @@ importJava "java.util.Map" where
     remove :: T a b -> a -> <Proc> (Maybe b)
     clear :: T a b -> <Proc> ()
 
+@inline
+getOrCreate :: T a b -> (a -> <e> b) ->  a -> <Proc,e> b
+getOrCreate m f k = match get m k with
+    Just v -> v
+    Nothing -> do
+        v = f k
+        put m k v
+        v  
+
 @inline
 iter :: (a -> b -> <e> ()) -> T a b -> <e,Proc> ()
 iter f m = MSet.iter (\entry -> f (keyOf entry) (valueOf entry)) (entrySet m)
@@ -53,6 +62,9 @@ importJava "gnu.trove.map.hash.THashMap" where
     @JavaName "<init>"
     createC :: Integer -> <Proc> T a b
 
+    @JavaName "<init>"
+    clone :: T a b -> <Proc> T a b
+
 fromEntryList :: [(a,b)] -> <Proc> T a b
 fromEntryList l = do
     result = createC (Prelude.length l)