summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-12 20:49:05 (GMT)
committerGitHub <noreply@github.com>2016-12-12 20:49:05 (GMT)
commit354e27c09603143cef43d666be5beaed8928c040 (patch)
tree7d85ff00a7c44c60e4797be332f4e24073eebeef /Xamarin.Forms.Build.Tasks
parente45bce1a64bd30c462abf51ab3b4eec69d5346aa (diff)
downloadxamarin-forms-354e27c09603143cef43d666be5beaed8928c040.zip
xamarin-forms-354e27c09603143cef43d666be5beaed8928c040.tar.gz
xamarin-forms-354e27c09603143cef43d666be5beaed8928c040.tar.bz2
[XamlC] Optimize Stloc/Ldloc (#614)
Diffstat (limited to 'Xamarin.Forms.Build.Tasks')
-rw-r--r--Xamarin.Forms.Build.Tasks/MethodBodyExtensions.cs20
1 files changed, 20 insertions, 0 deletions
diff --git a/Xamarin.Forms.Build.Tasks/MethodBodyExtensions.cs b/Xamarin.Forms.Build.Tasks/MethodBodyExtensions.cs
index f5bdc85..380cb59 100644
--- a/Xamarin.Forms.Build.Tasks/MethodBodyExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/MethodBodyExtensions.cs
@@ -12,6 +12,7 @@ namespace Xamarin.Forms.Build.Tasks
throw new ArgumentNullException(nameof(self));
self.OptimizeLongs();
+ self.OptimizeStLdLoc();
self.OptimizeMacros();
}
@@ -36,5 +37,24 @@ namespace Xamarin.Forms.Build.Tasks
self.Instructions.Insert(++i, Instruction.Create(OpCodes.Conv_I8));
}
}
+
+ static void OptimizeStLdLoc(this MethodBody self)
+ {
+ var method = self.Method;
+ for (var i = 0; i < self.Instructions.Count; i++) {
+ var instruction = self.Instructions[i];
+ if (instruction.OpCode.Code != Code.Stloc)
+ continue;
+ if (i + 1 >= self.Instructions.Count)
+ continue;
+ var next = self.Instructions[i + 1];
+ int num = ((VariableDefinition)instruction.Operand).Index;
+ var vardef = instruction.Operand;
+ if (next.OpCode.Code != Code.Ldloc || num != ((VariableDefinition)next.Operand).Index)
+ continue;
+ ExpandMacro(instruction, OpCodes.Dup, null);
+ ExpandMacro(next, OpCodes.Stloc, vardef);
+ }
+ }
}
} \ No newline at end of file