summaryrefslogtreecommitdiff
path: root/src/cli/runtime
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2006-06-11 21:07:38 +0000
committerRich Hickey <richhickey@gmail.com>2006-06-11 21:07:38 +0000
commit48bd0825f45f2255d851ba0f3236a454f6178ae0 (patch)
tree0a0fc414d2e80b70e9c4f8a318d7073978904024 /src/cli/runtime
parent8671005cec92c0ad806828eb4df605b17aadae4c (diff)
made Objs based upon ArrayIdentityMap, allowed out-of-transaction reads of current vals
Diffstat (limited to 'src/cli/runtime')
-rw-r--r--src/cli/runtime/IObj.cs22
-rw-r--r--src/cli/runtime/Obj.cs43
-rw-r--r--src/cli/runtime/TObj.cs33
-rw-r--r--src/cli/runtime/Transaction.cs7
4 files changed, 63 insertions, 42 deletions
diff --git a/src/cli/runtime/IObj.cs b/src/cli/runtime/IObj.cs
index c94ef5dc..6e101dbb 100644
--- a/src/cli/runtime/IObj.cs
+++ b/src/cli/runtime/IObj.cs
@@ -10,11 +10,17 @@
using System;
namespace clojure.lang
- {
- interface IObj
- {
- object put( IComparable key, object val);
- object get( IComparable key);
- bool has( IComparable key);
- }
- }
+ {
+ interface IObj
+ {
+ Object put(Object key, Object val);
+
+ Object get(Object key);
+
+ bool has(Object key);
+
+ IPersistentMap attrs();
+
+ void remove(Object key);
+ }
+ }
diff --git a/src/cli/runtime/Obj.cs b/src/cli/runtime/Obj.cs
index 269a4156..32684a6b 100644
--- a/src/cli/runtime/Obj.cs
+++ b/src/cli/runtime/Obj.cs
@@ -11,37 +11,38 @@
/* rich Mar 25, 2006 3:44:58 PM */
using System;
-using System.Collections.Specialized;
namespace clojure.lang
{
public class Obj : IObj
{
-
-HybridDictionary attrs;
-public static int INITIAL_SIZE = 7;
+volatile IPersistentMap _attrs = PersistentArrayIdentityMap.EMPTY;
-public Object put( IComparable key, Object val)
- {
- if(attrs == null)
- attrs = new HybridDictionary(INITIAL_SIZE);
- attrs[key] = val;
- return val;
+public Object put( Object key, Object val)
+ {
+ _attrs = _attrs.put(key, val);
+ return val;
}
-public Object get( IComparable key)
- {
- if(attrs == null)
- return null;
- return attrs[key];
+public Object get( Object key)
+ {
+ return _attrs.get(key);
}
-public bool has( IComparable key)
- {
- if (attrs == null)
- return false;
- return attrs.Contains(key);
- }
+public bool has( Object key){
+ return _attrs.contains(key);
+ }
+
+
+public IPersistentMap attrs() {
+ return _attrs;
+}
+
+public void remove(Object key) {
+ _attrs = _attrs.remove(key);
}
+
+}
+
} \ No newline at end of file
diff --git a/src/cli/runtime/TObj.cs b/src/cli/runtime/TObj.cs
index e9116cab..dcee3060 100644
--- a/src/cli/runtime/TObj.cs
+++ b/src/cli/runtime/TObj.cs
@@ -14,27 +14,38 @@ namespace clojure.lang
{
public class TObj : IObj{
-TRef attrs;
+TRef _attrs;
-public TObj() {
- this.attrs = Transaction.tref(new PersistentTree());
+public TObj(){
+ this._attrs = Transaction.tref(PersistentArrayIdentityMap.EMPTY);
}
-public Object put( IComparable key, Object val) {
- PersistentTree t = (PersistentTree) Transaction.get2( attrs);
- t = (PersistentTree) t.put(key, val);
- Transaction.set2(attrs,t);
+
+public Object put( Object key, Object val) {
+ IPersistentMap t = (IPersistentMap) Transaction.get2( _attrs);
+ t = t.put(key, val);
+ Transaction.set2(_attrs,t);
return val;
}
-public Object get( IComparable key) {
- PersistentTree t = (PersistentTree) Transaction.get2( attrs);
+public Object get( Object key) {
+ IPersistentMap t = (IPersistentMap) Transaction.get2( _attrs);
return t.get(key);
}
-public bool has( IComparable key) {
- PersistentTree t = (PersistentTree) Transaction.get2( attrs);
+public bool has( Object key) {
+ IPersistentMap t = (IPersistentMap) Transaction.get2( _attrs);
return t.contains(key);
}
+
+public IPersistentMap attrs() {
+ return (IPersistentMap) Transaction.get2(_attrs);
+}
+
+public void remove(Object key) {
+ IPersistentMap t = (IPersistentMap) Transaction.get2( _attrs);
+ t = t.remove(key);
+ Transaction.set2(_attrs,t);
+}
}
}
diff --git a/src/cli/runtime/Transaction.cs b/src/cli/runtime/Transaction.cs
index 21ff35bc..aaaac9dc 100644
--- a/src/cli/runtime/Transaction.cs
+++ b/src/cli/runtime/Transaction.cs
@@ -71,8 +71,11 @@ static public TRef tref(Object val) {
}
static public Object get2(TRef tref) {
- return ThreadLocalData.getTransaction().get(tref);
-}
+ Transaction trans = ThreadLocalData.getTransaction();
+ if(trans != null)
+ return trans.get(tref);
+ return getCurrent(tref).val;
+ }
static public Object set2(TRef tref, Object val) {
return ThreadLocalData.getTransaction().set(tref,val);