Permalink
Browse files

Avoid redundant cloning of Any type variable

  • Loading branch information...
1 parent ae3d3b7 commit de5e663fb85c563823505f0133cd6bca6cad6ebe @sorear committed May 29, 2011
Showing with 19 additions and 20 deletions.
  1. +1 −1 lib/Builtins.cs
  2. +1 −2 lib/Cursor.cs
  3. +17 −17 lib/Kernel.cs
View
@@ -849,7 +849,7 @@ class SubstrLValue: Variable {
P6any o1 = NominalCheck("$x", Kernel.AnyMO, v);
string r = o1.mo.mro_raw_Str.Get(v);
// XXX Failure
- if (r.Length == 0) return Kernel.NewROScalar(Kernel.AnyP);
+ if (r.Length == 0) return Kernel.AnyMO.typeVar;
return MakeInt((int)r[0]);
}
View
@@ -607,8 +607,7 @@ public Cursor(P6any proto, string text, P6any actions)
l.slots[1 /*rest*/ ] = new VarDeque();
return Kernel.NewROScalar(l);
} else {
- return caps.Count() != 0 ? caps[0] :
- Kernel.NewROScalar(Kernel.AnyP);
+ return caps.Count() != 0 ? caps[0] : Kernel.AnyMO.typeVar;
}
}
View
@@ -832,7 +832,7 @@ public class SubInfo {
if ((flags & SIG_F_DEFOUTER) != 0) {
Frame f = th;
if (outer_topic_key < 0) {
- src = Kernel.NewROScalar(Kernel.AnyP);
+ src = Kernel.AnyMO.typeVar;
goto gotit;
}
for (int i = 0; i < outer_topic_rank; i++) f = f.outer;
@@ -925,7 +925,7 @@ public class SubInfo {
public BValue AddHint(string name) {
if (hints == null)
hints = new Dictionary<string,BValue>();
- return hints[name] = new BValue(Kernel.NewROScalar(Kernel.AnyP));
+ return hints[name] = new BValue(Kernel.AnyMO.typeVar);
}
public void SetStringHint(string name, string value) {
@@ -1175,7 +1175,7 @@ public class Frame: P6any {
if (info.GetHint(name, out b))
return b.v;
else
- return Kernel.NewROScalar(Kernel.AnyP);
+ return Kernel.AnyMO.typeVar;
}
uint m = SubInfo.FilterForName(name);
while (csr != null) {
@@ -1185,7 +1185,7 @@ public class Frame: P6any {
}
csr = csr.outer;
}
- return Kernel.NewROScalar(Kernel.AnyP);
+ return Kernel.AnyMO.typeVar;
}
public Frame DynamicCaller() {
@@ -1652,7 +1652,7 @@ class IxAnyDeleteKey : IndexHandler {
P6any os = obj.Fetch();
if (!os.IsDefined())
- return Kernel.NewROScalar(Kernel.AnyP);
+ return Kernel.AnyMO.typeVar;
throw new NieczaException("Cannot use hash access on an object of type " + os.mo.name);
}
}
@@ -1702,7 +1702,7 @@ class IxCursorAtKey : IndexHandler {
}
P6any o = obj.Fetch();
if (!o.IsDefined())
- return Kernel.NewROScalar(Kernel.AnyP);
+ return Kernel.AnyMO.typeVar;
Cursor os = (Cursor)o;
return os.GetKey(key.Fetch().mo.mro_raw_Str.Get(key));
@@ -1716,7 +1716,7 @@ class IxCursorAtPos : IndexHandler {
P6any o = obj.Fetch();
if (!o.IsDefined())
- return Kernel.NewROScalar(Kernel.AnyP);
+ return Kernel.AnyMO.typeVar;
Cursor os = (Cursor)o;
return os.GetKey(Utils.N2S(key.Fetch().mo.mro_raw_Numeric.Get(key)));
@@ -1752,15 +1752,15 @@ class IxHashExistsKey : IndexHandler {
class IxHashDeleteKey : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any os = obj.Fetch();
- if (!os.IsDefined()) return Kernel.NewROScalar(Kernel.AnyP);
+ if (!os.IsDefined()) return Kernel.AnyMO.typeVar;
string ks = key.Fetch().mo.mro_raw_Str.Get(key);
VarHash h = Kernel.UnboxAny<VarHash>(os);
Variable r;
if (h.TryGetValue(ks, out r)) {
h.Remove(ks);
return r;
} else {
- return Kernel.NewROScalar(Kernel.AnyP);
+ return Kernel.AnyMO.typeVar;
}
}
}
@@ -1795,13 +1795,13 @@ class IxListAtPos : IndexHandler {
items.Push(rest.Shift());
}
if (ix < 0)
- return Kernel.NewROScalar(Kernel.AnyP);
+ return Kernel.AnyMO.typeVar;
if (items.Count() <= ix) {
if (extend) {
return new SimpleVariable(true, false, Kernel.AnyMO,
new ArrayViviHook(os, ix), Kernel.AnyP);
} else {
- return Kernel.NewROScalar(Kernel.AnyP);
+ return Kernel.AnyMO.typeVar;
}
}
return items[ix];
@@ -1831,7 +1831,7 @@ public class Kernel {
if (ModulesStarted == null) ModulesStarted = new HashSet<string>();
if (ModulesFinished == null) ModulesFinished = new HashSet<string>();
if (ModulesFinished.Contains(name))
- return NewROScalar(AnyP);
+ return AnyMO.typeVar;
if (ModulesStarted.Contains(name))
throw new NieczaException("Recursive module graph detected at " + name + ": " + JoinS(" ", ModulesStarted));
ModulesStarted.Add(name);
@@ -2433,7 +2433,7 @@ public class MMDCandidateLongname {
.TryGetValue(name, out v)) {
return v.v;
} else {
- return NewROScalar(AnyP);
+ return AnyMO.typeVar;
}
}
@@ -2469,7 +2469,7 @@ public class MMDCandidateLongname {
th = th.outer;
up--;
}
- return NewROScalar(AnyP);
+ return AnyMO.typeVar;
}
public static Variable DefaultNew(P6any proto, VarHash args) {
@@ -2618,7 +2618,7 @@ public class MMDCandidateLongname {
if (itemsl.Count() == 0) {
VarDeque restl = (VarDeque) dyl.GetSlot("rest");
if (restl.Count() == 0) {
- return NewROScalar(AnyP);
+ return AnyMO.typeVar;
}
goto slow;
}
@@ -3290,14 +3290,14 @@ class LastFrameNode {
tf.curDisp = de;
return tf;
} else {
- tf.caller.resultSlot = Kernel.NewROScalar(Kernel.AnyP);
+ tf.caller.resultSlot = AnyMO.typeVar;
return tf.caller;
}
} else if (type == SubInfo.ON_DIE) {
if (tf.lex == null)
tf.lex = new Dictionary<string,object>();
tf.lex["$*!"] = td;
- td = Kernel.NewROScalar(Kernel.AnyP);
+ td = AnyMO.typeVar;
}
tf.ip = tip;
tf.resultSlot = td;

0 comments on commit de5e663

Please sign in to comment.