Permalink
Browse files

Replace virtual method calls with type checks

  • Loading branch information...
1 parent 16054c7 commit 9852003adb87915403aee48cfdf5dc983b8af784 @sorear committed May 27, 2012
Showing with 9 additions and 13 deletions.
  1. +9 −12 lib/Kernel.cs
  2. +0 −1 lib/ObjModel.cs
View
@@ -62,9 +62,9 @@ public abstract class Variable : IFreeze {
public const int RW = 1;
public const int LIST = 2;
- public virtual int Mode { get { return RW; } }
- public bool Rw { get { return Mode == RW; } }
- public bool List { get { return Mode == LIST; } }
+ public virtual int Mode { get { return (this is ListVariable) ? LIST : (this is P6any) ? RO : RW; } }
+ public bool Rw { get { return !(this is P6any); } }
+ public bool List { get { return this is ListVariable; } }
public virtual void Vivify() { }
public virtual Variable Assign(Variable inp) {
Store(inp.Fetch());
@@ -214,7 +214,6 @@ public class NewArrayViviHook : ViviHook {
public sealed class ListVariable: Variable {
P6any val;
- public override int Mode { get { return LIST; } }
public ListVariable(P6any val) { this.val = val; }
@@ -277,7 +276,6 @@ public sealed class RWVariable: Variable {
val = v;
}
- public override int Mode { get { return RW; } }
public override void Vivify() {
ViviHook w = whence;
whence = null;
@@ -867,7 +865,7 @@ public sealed class RuntimeUnit : IFreeze {
}
static bool IsEmptyAggr(Variable v) {
- if (v.Mode != Variable.LIST) return false;
+ if (!v.List) return false;
P6any p = v.Fetch();
if (p.mo == Kernel.ArrayMO) {
return ((VarDeque)p.GetSlot(Kernel.ListMO, "$!items")).Count() == 0 &&
@@ -3226,7 +3224,7 @@ class IxParcelLISTSTORE : IndexHandler {
for (int i = 0; i < dsts.Length; i++) {
Variable d = dsts[i];
- if (d.Mode == Variable.LIST) {
+ if (d.List) {
srcs[i] = new P6opaque(Kernel.ListMO);
Kernel.IterToList(srcs[i], src);
src = new VarDeque();
@@ -5505,12 +5503,11 @@ internal class MMDCandidate : MultiCandidate {
}
public static Variable StashyMerge(Variable o, Variable n, string d1, string d2) {
- if (n.Mode != Variable.RO) return o;
- if (o.Mode != Variable.RO) return n;
-
- P6any oo = o.Fetch();
- P6any nn = n.Fetch();
+ P6any oo = o as P6any;
+ P6any nn = n as P6any;
+ if (oo == null) return n;
+ if (nn == null) return o;
if (oo == nn) return o;
if (!oo.IsDefined() && !nn.IsDefined() && oo.mo.who == nn.mo.who) {
View
@@ -12,7 +12,6 @@ public abstract class P6any: Variable, IFreeze {
throw new NieczaException("Writing to readonly scalar");
}
public override Variable GetVar() { return this; }
- public override int Mode { get { return RO; } }
public virtual object GetSlot(STable type, string name) {
throw new NieczaException("Representation " + ReprName() + " does not support attributes");

0 comments on commit 9852003

Please sign in to comment.