Skip to content

Avoid caching typeof result to decrease code size and improve perf #10715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

//#define OLD_ISF
Expand Down Expand Up @@ -608,7 +608,7 @@ private static void PersistStylusTip(DrawingAttributes da, Stream stream, GuidLi
using (MemoryStream localStream = new MemoryStream(6)) //reasonable default
{
Int32 stylusTip = Convert.ToInt32(da.StylusTip, System.Globalization.CultureInfo.InvariantCulture);
System.Runtime.InteropServices.VarEnum type = SerializationHelper.ConvertToVarEnum(PersistenceTypes.StylusTip, true);
System.Runtime.InteropServices.VarEnum type = SerializationHelper.ConvertToVarEnum(typeof(Int32), true);
ExtendedPropertySerializer.EncodeAttribute(KnownIds.StylusTip, stylusTip, type, localStream);

cbData += ExtendedPropertySerializer.EncodeAsISF(KnownIds.StylusTip, localStream.ToArray(), stream, guidList, 0, true);
Expand Down Expand Up @@ -680,12 +680,5 @@ private static void PersistWidthHeight(DrawingAttributes da, Stream stream, Guid


#endregion // Encoding

internal static class PersistenceTypes
{
public static readonly Type StylusTip = typeof(Int32);
public static readonly Type IsHollow = typeof(bool);
public static readonly Type StylusTipTransform = typeof(string);
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,10 @@ static TextDecoration()


// Initializations
Type typeofThis = typeof(TextDecoration);
PenProperty =
RegisterProperty("Pen",
typeof(Pen),
typeofThis,
typeof(TextDecoration),
null,
null,
null,
Expand All @@ -276,7 +275,7 @@ static TextDecoration()
PenOffsetProperty =
RegisterProperty("PenOffset",
typeof(double),
typeofThis,
typeof(TextDecoration),
0.0,
null,
null,
Expand All @@ -285,7 +284,7 @@ static TextDecoration()
PenOffsetUnitProperty =
RegisterProperty("PenOffsetUnit",
typeof(TextDecorationUnit),
typeofThis,
typeof(TextDecoration),
TextDecorationUnit.FontRecommended,
null,
new ValidateValueCallback(System.Windows.ValidateEnums.IsTextDecorationUnitValid),
Expand All @@ -294,7 +293,7 @@ static TextDecoration()
PenThicknessUnitProperty =
RegisterProperty("PenThicknessUnit",
typeof(TextDecorationUnit),
typeofThis,
typeof(TextDecoration),
TextDecorationUnit.FontRecommended,
null,
new ValidateValueCallback(System.Windows.ValidateEnums.IsTextDecorationUnitValid),
Expand All @@ -303,7 +302,7 @@ static TextDecoration()
LocationProperty =
RegisterProperty("Location",
typeof(TextDecorationLocation),
typeofThis,
typeof(TextDecoration),
TextDecorationLocation.Underline,
null,
new ValidateValueCallback(System.Windows.ValidateEnums.IsTextDecorationLocationValid),
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

//
Expand Down Expand Up @@ -160,14 +160,13 @@ private static CanExecuteChangedEventManager CurrentManager
{
get
{
Type managerType = typeof(CanExecuteChangedEventManager);
CanExecuteChangedEventManager manager = (CanExecuteChangedEventManager)GetCurrentManager(managerType);
CanExecuteChangedEventManager manager = (CanExecuteChangedEventManager)GetCurrentManager(typeof(CanExecuteChangedEventManager));

// at first use, create and register a new manager
if (manager == null)
{
manager = new CanExecuteChangedEventManager();
SetCurrentManager(managerType, manager);
SetCurrentManager(typeof(CanExecuteChangedEventManager), manager);
}

return manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,14 +901,13 @@ private static RequerySuggestedEventManager CurrentManager
{
get
{
Type managerType = typeof(RequerySuggestedEventManager);
RequerySuggestedEventManager manager = (RequerySuggestedEventManager)GetCurrentManager(managerType);
RequerySuggestedEventManager manager = (RequerySuggestedEventManager)GetCurrentManager(typeof(CanExecuteChangedEventManager));

// at first use, create and register a new manager
if (manager == null)
{
manager = new RequerySuggestedEventManager();
SetCurrentManager(managerType, manager);
SetCurrentManager(typeof(CanExecuteChangedEventManager), manager);
}

return manager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

//
Expand Down Expand Up @@ -93,14 +93,13 @@ private static DispatcherShutdownStartedEventManager CurrentManager
{
get
{
Type managerType = typeof(DispatcherShutdownStartedEventManager);
DispatcherShutdownStartedEventManager manager = (DispatcherShutdownStartedEventManager)GetCurrentManager(managerType);
DispatcherShutdownStartedEventManager manager = (DispatcherShutdownStartedEventManager)GetCurrentManager(typeof(DispatcherShutdownStartedEventManager));

// at first use, create and register a new manager
if (manager == null)
{
manager = new DispatcherShutdownStartedEventManager();
SetCurrentManager(managerType, manager);
SetCurrentManager(typeof(DispatcherShutdownStartedEventManager), manager);
}

return manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,34 @@ public partial class ByteAnimation :
/// </summary>
static ByteAnimation()
{
Type typeofProp = typeof(Byte?);
Type typeofThis = typeof(ByteAnimation);
PropertyChangedCallback propCallback = new PropertyChangedCallback(AnimationFunction_Changed);
ValidateValueCallback validateCallback = new ValidateValueCallback(ValidateFromToOrByValue);

FromProperty = DependencyProperty.Register(
"From",
typeofProp,
typeofThis,
typeof(Byte?),
typeof(ByteAnimation),
new PropertyMetadata((Byte?)null, propCallback),
validateCallback);

ToProperty = DependencyProperty.Register(
"To",
typeofProp,
typeofThis,
typeof(Byte?),
typeof(ByteAnimation),
new PropertyMetadata((Byte?)null, propCallback),
validateCallback);

ByProperty = DependencyProperty.Register(
"By",
typeofProp,
typeofThis,
typeof(Byte?),
typeof(ByteAnimation),
new PropertyMetadata((Byte?)null, propCallback),
validateCallback);

EasingFunctionProperty = DependencyProperty.Register(
"EasingFunction",
typeof(IEasingFunction),
typeofThis);
typeof(ByteAnimation));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,34 @@ public partial class ColorAnimation :
/// </summary>
static ColorAnimation()
{
Type typeofProp = typeof(Color?);
Type typeofThis = typeof(ColorAnimation);
PropertyChangedCallback propCallback = new PropertyChangedCallback(AnimationFunction_Changed);
ValidateValueCallback validateCallback = new ValidateValueCallback(ValidateFromToOrByValue);

FromProperty = DependencyProperty.Register(
"From",
typeofProp,
typeofThis,
typeof(Color?),
typeof(ColorAnimation),
new PropertyMetadata((Color?)null, propCallback),
validateCallback);

ToProperty = DependencyProperty.Register(
"To",
typeofProp,
typeofThis,
typeof(Color?),
typeof(ColorAnimation),
new PropertyMetadata((Color?)null, propCallback),
validateCallback);

ByProperty = DependencyProperty.Register(
"By",
typeofProp,
typeofThis,
typeof(Color?),
typeof(ColorAnimation),
new PropertyMetadata((Color?)null, propCallback),
validateCallback);

EasingFunctionProperty = DependencyProperty.Register(
"EasingFunction",
typeof(IEasingFunction),
typeofThis);
typeof(ColorAnimation));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,34 @@ public partial class DecimalAnimation :
/// </summary>
static DecimalAnimation()
{
Type typeofProp = typeof(Decimal?);
Type typeofThis = typeof(DecimalAnimation);
PropertyChangedCallback propCallback = new PropertyChangedCallback(AnimationFunction_Changed);
ValidateValueCallback validateCallback = new ValidateValueCallback(ValidateFromToOrByValue);

FromProperty = DependencyProperty.Register(
"From",
typeofProp,
typeofThis,
typeof(Decimal?),
typeof(DecimalAnimation),
new PropertyMetadata((Decimal?)null, propCallback),
validateCallback);

ToProperty = DependencyProperty.Register(
"To",
typeofProp,
typeofThis,
typeof(Decimal?),
typeof(DecimalAnimation),
new PropertyMetadata((Decimal?)null, propCallback),
validateCallback);

ByProperty = DependencyProperty.Register(
"By",
typeofProp,
typeofThis,
typeof(Decimal?),
typeof(DecimalAnimation),
new PropertyMetadata((Decimal?)null, propCallback),
validateCallback);

EasingFunctionProperty = DependencyProperty.Register(
"EasingFunction",
typeof(IEasingFunction),
typeofThis);
typeof(DecimalAnimation));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,34 @@ public partial class DoubleAnimation :
/// </summary>
static DoubleAnimation()
{
Type typeofProp = typeof(Double?);
Type typeofThis = typeof(DoubleAnimation);
PropertyChangedCallback propCallback = new PropertyChangedCallback(AnimationFunction_Changed);
ValidateValueCallback validateCallback = new ValidateValueCallback(ValidateFromToOrByValue);

FromProperty = DependencyProperty.Register(
"From",
typeofProp,
typeofThis,
typeof(Double?),
typeof(DoubleAnimation),
new PropertyMetadata((Double?)null, propCallback),
validateCallback);

ToProperty = DependencyProperty.Register(
"To",
typeofProp,
typeofThis,
typeof(Double?),
typeof(DoubleAnimation),
new PropertyMetadata((Double?)null, propCallback),
validateCallback);

ByProperty = DependencyProperty.Register(
"By",
typeofProp,
typeofThis,
typeof(Double?),
typeof(DoubleAnimation),
new PropertyMetadata((Double?)null, propCallback),
validateCallback);

EasingFunctionProperty = DependencyProperty.Register(
"EasingFunction",
typeof(IEasingFunction),
typeofThis);
typeof(DoubleAnimation));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,34 @@ public partial class Int16Animation :
/// </summary>
static Int16Animation()
{
Type typeofProp = typeof(Int16?);
Type typeofThis = typeof(Int16Animation);
PropertyChangedCallback propCallback = new PropertyChangedCallback(AnimationFunction_Changed);
ValidateValueCallback validateCallback = new ValidateValueCallback(ValidateFromToOrByValue);

FromProperty = DependencyProperty.Register(
"From",
typeofProp,
typeofThis,
typeof(Int16?),
typeof(Int16Animation),
new PropertyMetadata((Int16?)null, propCallback),
validateCallback);

ToProperty = DependencyProperty.Register(
"To",
typeofProp,
typeofThis,
typeof(Int16?),
typeof(Int16Animation),
new PropertyMetadata((Int16?)null, propCallback),
validateCallback);

ByProperty = DependencyProperty.Register(
"By",
typeofProp,
typeofThis,
typeof(Int16?),
typeof(Int16Animation),
new PropertyMetadata((Int16?)null, propCallback),
validateCallback);

EasingFunctionProperty = DependencyProperty.Register(
"EasingFunction",
typeof(IEasingFunction),
typeofThis);
typeof(Int16Animation));
}


Expand Down
Loading