Skip to content

Commit

Permalink
chore: avoid duplicate GetType calls (#10295)
Browse files Browse the repository at this point in the history
Co-authored-by: Yufei Huang <[email protected]>
  • Loading branch information
SimonCropp and yufeih authored Oct 19, 2024
1 parent a436afe commit 59ff064
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/Docfx.Common/EntityMergers/ReflectionEntityMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ public void Merge(ref object source, object overrides, IMergeContext context)
{
continue;
}
if (o.GetType().IsValueType)

var type = o.GetType();
if (type.IsValueType)
{
var defaultValue = Activator.CreateInstance(o.GetType());
var defaultValue = Activator.CreateInstance(type);
if (object.Equals(defaultValue, o))
{
continue;
Expand Down Expand Up @@ -180,9 +182,11 @@ public void Merge(ref object source, object overrides, IMergeContext context)
{
continue;
}
if (o.GetType().IsValueType)

var type = o.GetType();
if (type.IsValueType)
{
var defaultValue = Activator.CreateInstance(o.GetType());
var defaultValue = Activator.CreateInstance(type);
if (object.Equals(defaultValue, o))
{
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public override BlockState TryOpen(BlockProcessor processor)
block.SetData(typeof(HtmlAttributes), htmlAttributes);
}

if (extension.GetType() == typeof(ImageExtension))
var type = extension.GetType();
if (type == typeof(ImageExtension))
{
if (!ImageExtension.RequiresClosingTripleColon(attributes))
{
Expand All @@ -77,7 +78,7 @@ public override BlockState TryOpen(BlockProcessor processor)
block.EndingTripleColons = true;
return BlockState.ContinueDiscard;
}
else if (extension.GetType() == typeof(VideoExtension))
else if (type == typeof(VideoExtension))
{
if (!VideoExtension.RequiresClosingTripleColon(attributes))
{
Expand Down Expand Up @@ -107,9 +108,8 @@ public override BlockState TryContinue(BlockProcessor processor, Block block)
var colonBlock = (TripleColonBlock) block;
var endingTripleColons = colonBlock.EndingTripleColons;

if (colonBlock.Extension.GetType() != typeof(ImageExtension) ||
colonBlock.Extension.GetType() != typeof(VideoExtension) ||
endingTripleColons)
Type type = ((TripleColonBlock)block).Extension.GetType();
if (type != typeof(ImageExtension) || type != typeof(VideoExtension) || endingTripleColons)
{
if (processor.IsBlankLine)
{
Expand Down

0 comments on commit 59ff064

Please sign in to comment.