Skip to content

Commit

Permalink
Generate Ret instead of Br to end
Browse files Browse the repository at this point in the history
  • Loading branch information
vanifatovvlad committed Apr 8, 2023
1 parent 15b59d3 commit 5b68255
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions CodeGen/AtomWeaverV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ private struct AtomSetterMethodWeaver
private PropertyDefinition _property;

private Instruction _nullCheckEndInstruction;
private Instruction _preReturnInstruction;

private MethodReference _compAndInvalidateMethod;
private MethodReference _throwIfDisposedMethod;
Expand All @@ -299,7 +298,6 @@ public AtomSetterMethodWeaver(AtomWeaverV2 weaver, PropertyDefinition property,
_property = property;

_nullCheckEndInstruction = Instruction.Create(OpCodes.Nop);
_preReturnInstruction = Instruction.Create(OpCodes.Nop);

var propertyType = property.PropertyType;
_compAndInvalidateMethod =
Expand All @@ -314,8 +312,6 @@ public void Weave()
var index = 0;
Prepend(ref index, instructions);

body.Instructions.Insert(body.Instructions.Count - 1, _preReturnInstruction);

body.OptimizeMacros();
}

Expand All @@ -331,14 +327,15 @@ private void Prepend(ref int ind, IList<Instruction> il)
il.Insert(ind++, Instruction.Create(OpCodes.Ldfld, _atomField));
il.Insert(ind++, Instruction.Create(OpCodes.Brfalse, _nullCheckEndInstruction));

// atom.Invalidate()
// if (atom.CompareAndInvalidate()) goto nullCheckEnd;
il.Insert(ind++, Instruction.Create(OpCodes.Ldarg_0));
il.Insert(ind++, Instruction.Create(OpCodes.Ldfld, _atomField));
il.Insert(ind++, Instruction.Create(OpCodes.Ldarg_1));
il.Insert(ind++, Instruction.Create(OpCodes.Callvirt, _compAndInvalidateMethod));
il.Insert(ind++, Instruction.Create(OpCodes.Brtrue, _nullCheckEndInstruction));

il.Insert(ind++, Instruction.Create(OpCodes.Br, _preReturnInstruction));
// return;
il.Insert(ind++, Instruction.Create(OpCodes.Ret));

il.Insert(ind++, _nullCheckEndInstruction);
}
Expand Down

0 comments on commit 5b68255

Please sign in to comment.