Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Nov 17, 2024
1 parent d4f1bd9 commit b134a01
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/PCRE.NET/Dfa/PcreDfaMatchResult.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using PCRE.Internal;

Expand Down
17 changes: 12 additions & 5 deletions src/PCRE.NET/Internal/PriorityCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ internal class PriorityCache<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TVal
private readonly Func<TKey, TValue> _valueFactory;
private readonly IEqualityComparer<TKey> _keyComparer;
private readonly LinkedList<CacheItem> _cache = new();

#if NET9_0_OR_GREATER
private readonly Lock _lock = new();
#else
private readonly object _lock = new();
#endif

private int _cacheSize;
private object? _head;

Expand All @@ -30,7 +37,7 @@ public int CacheSize
if (value < 0)
throw new ArgumentException("Invalid cache size.");

lock (_cache)
lock (_lock)
{
while (_cache.Count > value)
_cache.RemoveLast();
Expand All @@ -47,7 +54,7 @@ public int Count
{
get
{
lock (_cache)
lock (_lock)
{
return _cache.Count;
}
Expand All @@ -65,7 +72,7 @@ public TValue GetOrAdd(TKey key)
if (_cacheSize == 0)
return _valueFactory(key);

lock (_cache)
lock (_lock)
{
for (var node = _cache.First; node != null; node = node.Next)
{
Expand All @@ -82,7 +89,7 @@ public TValue GetOrAdd(TKey key)
var item = new CacheItem(key, keyHash, _valueFactory(key));
Volatile.Write(ref _head, item);

lock (_cache)
lock (_lock)
{
_cache.AddFirst(item);
if (_cache.Count > _cacheSize)
Expand All @@ -100,7 +107,7 @@ private class CacheItem(TKey key, int keyHashCode, TValue value)

public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
lock (_cache)
lock (_lock)
{
return _cache.Select(i => new KeyValuePair<TKey, TValue>(i.Key, i.Value))
.ToList()
Expand Down
2 changes: 1 addition & 1 deletion src/PCRE.NET/PCRE.NET.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net9.0;net5.0;netstandard2.0</TargetFrameworks>
<!--suppress MsbuildTargetFrameworkTagInspection -->
<TargetFrameworks Condition="'$(ForceNetStandard)' == 'true'">netstandard2.0</TargetFrameworks>
<RootNamespace>PCRE</RootNamespace>
Expand Down
2 changes: 1 addition & 1 deletion src/PCRE.NET/PcreCalloutInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal PcreCalloutInfo(ref Native.pcre2_callout_enumerate_block info)
/// <remarks>
/// When the callout is at the end of the pattern, the length is zero. When the callout precedes an opening parenthesis,
/// the length includes meta characters that follow the parenthesis. For example, in a callout before an assertion such as
/// <c>(?=ab)</c> the length is 3. For an an alternation bar or a closing parenthesis, the length is one, unless a closing
/// <c>(?=ab)</c> the length is 3. For an alternation bar or a closing parenthesis, the length is one, unless a closing
/// parenthesis is followed by a quantifier, in which case its length is included.
/// </remarks>
public int NextPatternItemLength { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/PCRE.NET/PcreMatchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum PcreMatchOptions : long
/// <remarks>
/// <para>
/// The <see cref="Anchored"/> option limits <c>pcre2_match()</c> to matching at the first matching position.
/// If a pattern was compiled with <see cref="PcreOptions.Anchored"/>, or turned out to be anchored by virtue of its contents, it cannot be made unachored at matching time.
/// If a pattern was compiled with <see cref="PcreOptions.Anchored"/>, or turned out to be anchored by virtue of its contents, it cannot be made unanchored at matching time.
/// </para>
/// <para>
/// Note that setting the option at match time disables JIT matching.
Expand Down
2 changes: 1 addition & 1 deletion src/PCRE.NET/PcreSubstituteOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum PcreSubstituteOptions : long
/// <remarks>
/// <para>
/// The <see cref="Anchored"/> option limits <c>pcre2_match()</c> to matching at the first matching position.
/// If a pattern was compiled with <see cref="PcreOptions.Anchored"/>, or turned out to be anchored by virtue of its contents, it cannot be made unachored at matching time.
/// If a pattern was compiled with <see cref="PcreOptions.Anchored"/>, or turned out to be anchored by virtue of its contents, it cannot be made unanchored at matching time.
/// </para>
/// <para>
/// Note that setting the option at match time disables JIT matching.
Expand Down

0 comments on commit b134a01

Please sign in to comment.