Skip to content

Commit

Permalink
Counter cache dont need to be concurrent (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Apr 4, 2024
1 parent 2334ecc commit d10b73a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters</NoWarn>
<Version>23.7.0</Version>
<Version>23.7.1</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/Verify/Counter_Date.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace VerifyTests;

public partial class Counter
{
ConcurrentDictionary<Date, (int intValue, string stringValue)> dateCache = [];
Dictionary<Date, (int intValue, string stringValue)> dateCache = [];
static Dictionary<Date, string> globalNamedDates = [];
int currentDate;

Expand Down
2 changes: 1 addition & 1 deletion src/Verify/Counter_DateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public partial class Counter
{
ConcurrentDictionary<DateTime, (int intValue, string stringValue)> dateTimeCache = new(new DateTimeComparer());
Dictionary<DateTime, (int intValue, string stringValue)> dateTimeCache = new(new DateTimeComparer());
static Dictionary<DateTime, string> globalNamedDateTimes = [];

class DateTimeComparer : IEqualityComparer<DateTime>
Expand Down
2 changes: 1 addition & 1 deletion src/Verify/Counter_DateTimeOffset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public partial class Counter
{
ConcurrentDictionary<DateTimeOffset, (int intValue, string stringValue)> dateTimeOffsetCache = new(new DateTimeOffsetComparer());
Dictionary<DateTimeOffset, (int intValue, string stringValue)> dateTimeOffsetCache = new(new DateTimeOffsetComparer());
static Dictionary<DateTimeOffset, string> globalNamedDateTimeOffsets = [];

class DateTimeOffsetComparer :
Expand Down
2 changes: 1 addition & 1 deletion src/Verify/Counter_Guid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public partial class Counter
{
ConcurrentDictionary<Guid, (int intValue, string stringValue)> guidCache = [];
Dictionary<Guid, (int intValue, string stringValue)> guidCache = [];
static Dictionary<Guid, string> globalNamedGuids = [];
int currentGuid;

Expand Down
2 changes: 1 addition & 1 deletion src/Verify/Counter_Time.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace VerifyTests;

public partial class Counter
{
ConcurrentDictionary<Time, (int intValue, string stringValue)> timeCache = [];
Dictionary<Time, (int intValue, string stringValue)> timeCache = [];
static Dictionary<Time, string> globalNamedTimes = [];
int currentTime;

Expand Down
11 changes: 11 additions & 0 deletions src/Verify/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ public static void RemoveEmptyLines(this StringBuilder builder)
public static string Remove(this string value, string toRemove) =>
value.Replace(toRemove, "");

public static TValue GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> factory)
where TKey : notnull
{
if (dictionary.TryGetValue(key, out var value))
{
return value;
}

return dictionary[key] = factory(key);
}

public static void ReplaceIfLonger(this StringBuilder builder, string oldValue, string newValue)
{
if (builder.Length < oldValue.Length)
Expand Down

0 comments on commit d10b73a

Please sign in to comment.