Skip to content

Commit 7224040

Browse files
Optimize message formatting (nunit#4788)
Move expensive formatting checks to the end
1 parent e59e1bf commit 7224040

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/NUnitFramework/framework/Constraints/MsgUtils.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ static MsgUtils()
6565
// Initialize formatter to default for values of indeterminate type.
6666
DefaultValueFormatter = FormatValueWithoutThrowing;
6767

68+
AddFormatter(next => val => TryFormatTuple(val, TypeHelper.IsTuple, GetValueFromTuple) ?? next(val));
69+
6870
AddFormatter(next => val => val is ValueType ? string.Format(Fmt_ValueType, val) : next(val));
6971

72+
AddFormatter(next => val => TryFormatKeyValuePair(val) ?? next(val));
73+
74+
AddFormatter(next => val => TryFormatTuple(val, TypeHelper.IsValueTuple, GetValueFromValueTuple) ?? next(val));
75+
7076
AddFormatter(next => val => val is DateTime value ? FormatDateTime(value) : next(val));
7177

7278
AddFormatter(next => val => val is DateTimeOffset value ? FormatDateTimeOffset(value) : next(val));
@@ -86,12 +92,6 @@ static MsgUtils()
8692
AddFormatter(next => val => val is DictionaryEntry de ? FormatKeyValuePair(de.Key, de.Value) : next(val));
8793

8894
AddFormatter(next => val => val is Array valArray ? FormatArray(valArray) : next(val));
89-
90-
AddFormatter(next => val => TryFormatKeyValuePair(val) ?? next(val));
91-
92-
AddFormatter(next => val => TryFormatTuple(val, TypeHelper.IsTuple, GetValueFromTuple) ?? next(val));
93-
94-
AddFormatter(next => val => TryFormatTuple(val, TypeHelper.IsValueTuple, GetValueFromValueTuple) ?? next(val));
9595
}
9696

9797
#if NETFRAMEWORK

0 commit comments

Comments
 (0)