Avoid creation of nullable to improve perf and small code cleanup
Rob Mensching committed
Jul 10, 2020 at 21:21 UTC
bff4dd77d9d04f587d3f1948c9d569b15b2ca347
3 files changed
+33
-33
src/WixToolset.Data/IntermediateFieldValue.cs
+2
-2
@@ -17,11 +17,11 @@ namespace WixToolset.Data
17
18
public static explicit operator bool(IntermediateFieldValue value) => value.AsBool();
19
20
- public static explicit operator bool? (IntermediateFieldValue value) => value.AsNullableBool();
20
+ public static explicit operator bool?(IntermediateFieldValue value) => value.AsNullableBool();
21
22
public static explicit operator int(IntermediateFieldValue value) => value.AsNumber();
23
24
- public static explicit operator int? (IntermediateFieldValue value) => value.AsNullableNumber();
24
+ public static explicit operator int?(IntermediateFieldValue value) => value.AsNullableNumber();
25
26
public static explicit operator IntermediateFieldPathValue(IntermediateFieldValue value) => value.AsPath();
27
src/WixToolset.Data/IntermediateFieldValueExtensions.cs
+29
-29
@@ -8,17 +8,7 @@ namespace WixToolset.Data
8
{
9
public static bool AsBool(this IntermediateFieldValue value)
10
{
11
- var result = value.AsNullableBool();
12
- return result.HasValue && result.Value;
13
- }
14
-
15
- public static bool? AsNullableBool(this IntermediateFieldValue value)
16
- {
17
- if (value?.Data == null)
18
- {
19
- return null;
20
- }
21
- else if (value.Data is bool b)
11
+ if (value.Data is bool b)
12
{
13
return b;
14
}
@@ -45,26 +35,26 @@ namespace WixToolset.Data
35
return (bool)value.Data;
36
}
37
48
- public static long AsLargeNumber(this IntermediateFieldValue value)
38
+ public static bool? AsNullableBool(this IntermediateFieldValue value)
39
{
50
- var result = value.AsNullableLargeNumber();
51
- return result ?? 0;
40
+ if (value?.Data == null)
41
+ {
42
+ return null;
43
+ }
44
+
45
+ return value.AsBool();
46
}
47
54
- public static long? AsNullableLargeNumber(this IntermediateFieldValue value)
48
+ public static long AsLargeNumber(this IntermediateFieldValue value)
49
{
56
- if (value?.Data == null)
50
+ if (value.Data is long l)
51
{
58
- return null;
52
+ return l;
53
}
54
else if (value.Data is int n)
55
{
56
return n;
57
}
64
- else if (value.Data is long l)
65
- {
66
- return l;
67
- }
58
else if (value.Data is bool b)
59
{
60
return b ? 1 : 0;
@@ -84,19 +74,19 @@ namespace WixToolset.Data
74
return (long)value.Data;
75
}
76
87
- public static int AsNumber(this IntermediateFieldValue value)
88
- {
89
- var result = value.AsNullableNumber();
90
- return result ?? 0;
91
- }
92
-
93
- public static int? AsNullableNumber(this IntermediateFieldValue value)
77
+ public static long? AsNullableLargeNumber(this IntermediateFieldValue value)
78
{
79
if (value?.Data == null)
80
{
81
return null;
82
}
99
- else if (value.Data is int n)
83
+
84
+ return value.AsLargeNumber();
85
+ }
86
+
87
+ public static int AsNumber(this IntermediateFieldValue value)
88
+ {
89
+ if (value.Data is int n)
90
{
91
return n;
92
}
@@ -123,6 +113,16 @@ namespace WixToolset.Data
113
return (int)value.Data;
114
}
115
116
+ public static int? AsNullableNumber(this IntermediateFieldValue value)
117
+ {
118
+ if (value?.Data == null)
119
+ {
120
+ return null;
121
+ }
122
+
123
+ return value.AsNumber();
124
+ }
125
+
126
public static IntermediateFieldPathValue AsPath(this IntermediateFieldValue value)
127
{
128
return (IntermediateFieldPathValue)value?.Data;
src/WixToolset.Data/Symbols/WixSimpleReferenceSymbol.cs
+2
-2
@@ -28,7 +28,7 @@ namespace WixToolset.Data.Symbols
28
PrimaryKeys,
29
}
30
31
- [DebuggerDisplay("{SymbolicName}")]
31
+ [DebuggerDisplay("{SymbolicName,nq}")]
32
public class WixSimpleReferenceSymbol : IntermediateSymbol
33
{
34
public WixSimpleReferenceSymbol() : base(SymbolDefinitions.WixSimpleReference, null, null)
@@ -57,6 +57,6 @@ namespace WixToolset.Data.Symbols
57
/// Gets the symbolic name.
58
/// </summary>
59
/// <value>Symbolic name.</value>
60
- public string SymbolicName => String.Concat(this.Table, ":", this.PrimaryKeys);
60
+ public string SymbolicName => String.Concat("Ref ", this.Table, ":", this.PrimaryKeys);
61
}
62
}
\ No newline at end of file