Skip to content

Commit 8f49040

Browse files
committed
Fixes an issue where cache was not constructed without rules being loaded
1 parent 90a55e3 commit 8f49040

7 files changed

Lines changed: 721 additions & 26 deletions

File tree

DistillNET/DistillNET.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
<RepositoryUrl>https://github.com/TechnikEmpire/DistillNET</RepositoryUrl>
1010
<Description>DistillNET is a library for matching and filtering HTTP requests URLs using the Adblock Plus Filter format.</Description>
1111
<Copyright>Copyright © 2017 - 2018 Jesse Nicholson</Copyright>
12-
<Version>1.6.1</Version>
12+
<Version>1.6.2</Version>
1313
<Authors>Jesse Nicholson</Authors>
1414
<Company>Technik Empire</Company>
1515
<PackageTags>DistillNET Adblock AdblockPlus Adblock-Plus URL-Filter URL-Filtering Content-Filter Filter</PackageTags>
16-
<PackageReleaseNotes>Upgrade depends to .NET core 2.1 release.</PackageReleaseNotes>
17-
<AssemblyVersion>1.6.1.0</AssemblyVersion>
18-
<FileVersion>1.6.11.0</FileVersion>
16+
<PackageReleaseNotes>Fixes an issue where cache is not built on an instance where no rules are ever loaded.</PackageReleaseNotes>
17+
<AssemblyVersion>1.6.2.0</AssemblyVersion>
18+
<FileVersion>1.6.2.0</FileVersion>
1919
</PropertyGroup>
2020

2121
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright © 2018 Jesse Nicholson
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
using System.Linq;
9+
using System.Runtime.CompilerServices;
10+
11+
namespace DistillNET.Extensions
12+
{
13+
internal static class CharExtensions
14+
{
15+
private static readonly char[] _lower;
16+
private static readonly char[] _upper;
17+
18+
static CharExtensions()
19+
{
20+
_lower = new char[char.MaxValue];
21+
_upper = new char[char.MaxValue];
22+
Enumerable.Range(0, char.MaxValue).Select(x =>
23+
{
24+
_lower[x] = char.ToLowerInvariant((char)x);
25+
_upper[x] = char.ToUpperInvariant((char)x);
26+
return x;
27+
});
28+
}
29+
30+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
31+
public static char ToUpperFast(this char c)
32+
{
33+
return _upper[c];
34+
}
35+
36+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
37+
public static char ToLowerFast(this char c)
38+
{
39+
return _lower[c];
40+
}
41+
}
42+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Copyright © 2018 Jesse Nicholson
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Text;
11+
12+
namespace DistillNET.Extensions
13+
{
14+
internal static class MemoryExtensions
15+
{
16+
/// <summary>
17+
/// Determines if this ReadOnlyMemory begins with the same character sequence as the supplied string.
18+
/// </summary>
19+
/// <param name="str">
20+
/// This string.
21+
/// </param>
22+
/// <param name="other">
23+
/// The ReadOnlyMemory to compare the beginning of this
24+
/// </param>
25+
/// <returns>
26+
/// </returns>
27+
/// <remarks>
28+
/// This method is used rather than the built in .net equivalent for the sake of speed. The
29+
/// built in method invokes various internationalization methods inside the .net framework
30+
/// that simply are not necessary for our purposes.
31+
/// </remarks>
32+
public static bool StartsWithQuick(this ReadOnlyMemory<char> str, ReadOnlyMemory<char> other)
33+
{
34+
return str.Span.StartsWithQuick(other.Span);
35+
}
36+
37+
/// <summary>
38+
/// Gets the next position of a character that would indicate the end of an address or domain
39+
/// anchor string, if any.
40+
/// </summary>
41+
/// <param name="str">
42+
/// This string.
43+
/// </param>
44+
/// <param name="startIndex">
45+
/// The index to begin searching at.
46+
/// </param>
47+
/// <returns>
48+
/// A positive value indicating the index of a matched character in the event that one is
49+
/// found, a negative number in the event that no such character is found.
50+
/// </returns>
51+
public static int IndexOfAnchorEnd(this ReadOnlyMemory<char> str, int startIndex = 0)
52+
{
53+
return str.Span.IndexOfAnchorEnd(startIndex);
54+
}
55+
56+
public static int IndexOfQuick(this ReadOnlyMemory<char> str, char what, int startIndex = 0)
57+
{
58+
return str.Span.IndexOfQuick(what, startIndex);
59+
}
60+
61+
public static int IndexOfQuickICase(this ReadOnlyMemory<char> str, char what, int startIndex = 0)
62+
{
63+
return str.Span.IndexOfQuickICase(what, startIndex);
64+
}
65+
66+
public static int IndexOfQuick(this ReadOnlyMemory<char> str, ReadOnlyMemory<char> what, int startIndex = 0)
67+
{
68+
return str.Span.IndexOfQuick(what.Span, startIndex);
69+
}
70+
71+
public static int IndexOfQuickICase(this ReadOnlyMemory<char> str, ReadOnlyMemory<char> what, int startIndex = 0)
72+
{
73+
return str.Span.IndexOfQuickICase(what.Span, startIndex);
74+
}
75+
76+
public static bool EqualsAt(this ReadOnlyMemory<char> str, ReadOnlyMemory<char> what, int index)
77+
{
78+
return str.Span.EqualsAt(what.Span, index);
79+
}
80+
81+
public static bool EqualsAtICase(this ReadOnlyMemory<char> str, ReadOnlyMemory<char> what, int index)
82+
{
83+
return str.Span.EqualsAtICase(what.Span, index);
84+
}
85+
86+
public static ReadOnlyMemory<char> TrimQuick(this ReadOnlyMemory<char> str)
87+
{
88+
bool trimming = true;
89+
while (trimming && str.Length > 0)
90+
{
91+
if (char.IsWhiteSpace(str.Span[0]))
92+
{
93+
str = str.Slice(1);
94+
continue;
95+
}
96+
97+
if (char.IsWhiteSpace(str.Span[str.Length - 1]))
98+
{
99+
str = str.Slice(0, str.Length - 1);
100+
continue;
101+
}
102+
103+
trimming = false;
104+
}
105+
return str;
106+
}
107+
108+
public static int LastIndexOfQuick(this ReadOnlyMemory<char> str, ReadOnlyMemory<char> what)
109+
{
110+
return str.Span.LastIndexOfQuick(what.Span);
111+
}
112+
113+
public static int LastIndexOfQuickICase(this ReadOnlyMemory<char> str, ReadOnlyMemory<char> what)
114+
{
115+
return str.Span.LastIndexOfQuickICase(what.Span);
116+
}
117+
118+
public static List<ReadOnlyMemory<char>> Split(this ReadOnlyMemory<char> str, ReadOnlyMemory<char> what)
119+
{
120+
var retVal = new List<ReadOnlyMemory<char>>();
121+
122+
var firstIndex = str.IndexOfQuick(what, 0);
123+
124+
if (firstIndex > -1)
125+
{
126+
do
127+
{
128+
retVal.Add(str.Slice(0, firstIndex));
129+
str = str.Slice(firstIndex + what.Length);
130+
firstIndex = str.IndexOfQuick(what, 0);
131+
} while (firstIndex > -1);
132+
133+
if (str.Length > 0)
134+
{
135+
retVal.Add(str);
136+
}
137+
}
138+
else
139+
{
140+
retVal.Add(str);
141+
}
142+
143+
return retVal;
144+
}
145+
}
146+
}

0 commit comments

Comments
 (0)