Skip to content

Commit 49e778b

Browse files
authored
Added AsSpan() and AsMemory() methods to ICharTermAttribute, CharsRef, and BytesRef (#1192)
* .build/dependencies.props: Added dependency on Microsoft.Bcl.Memory for Index/Range and Utf8 support on .NET Framework and .NET Standard 2.0. Bumped System.Memory to 4.6.3 (Required by Microsoft.Bcl.Memory). * Added Lucene.Net.MemoryExtensions class with support for AsSpan() and AsMemory() overloads for ICharTermAttribute. * Lucene.Net.Util.CharsRef: Added AsSpan(), AsMemory(), ctor, CopyChars(), and Append() methods to support System.Memory types. * Lucene.Net.Util.BytesRef: Added AsSpan(), AsMemory(), ctor, CopyChars(), and Append() methods to support System.Memory types. * Lucene.Net.Tests/Support/TestMemoryExtensions.cs: Added LuceneNetAttribute and links to the sources the file is based on.
1 parent 2067df7 commit 49e778b

14 files changed

Lines changed: 2728 additions & 6 deletions

File tree

.build/dependencies.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<LuceneNetCodeAnalysisDevPackageVersion>1.0.0-alpha.6</LuceneNetCodeAnalysisDevPackageVersion>
4444
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.3.0</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
4545
<MicrosoftAspNetCoreTestHostPackageVersion>8.0.19</MicrosoftAspNetCoreTestHostPackageVersion>
46+
<MicrosoftBclMemoryPackageVersion>10.0.0-rc.1.25451.107</MicrosoftBclMemoryPackageVersion>
4647
<MicrosoftCodeAnalysisAnalyzersPackageVersion>2.9.8</MicrosoftCodeAnalysisAnalyzersPackageVersion>
4748
<MicrosoftCodeAnalysisCSharpPackageVersion>2.6.1</MicrosoftCodeAnalysisCSharpPackageVersion>
4849
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>$(MicrosoftCodeAnalysisCSharpPackageVersion)</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
@@ -70,7 +71,7 @@
7071
<RandomizedTestingGeneratorsPackageVersion>2.7.8</RandomizedTestingGeneratorsPackageVersion>
7172
<SharpZipLibPackageVersion>1.4.2</SharpZipLibPackageVersion>
7273
<Spatial4nPackageVersion>0.4.1.1</Spatial4nPackageVersion>
73-
<SystemMemoryPackageVersion>4.5.5</SystemMemoryPackageVersion>
74+
<SystemMemoryPackageVersion>4.6.3</SystemMemoryPackageVersion>
7475
<SystemNetHttpPackageVersion>4.3.4</SystemNetHttpPackageVersion>
7576
<SystemReflectionEmitPackageVersion>4.3.0</SystemReflectionEmitPackageVersion>
7677
<SystemReflectionEmitILGenerationPackageVersion>4.3.0</SystemReflectionEmitILGenerationPackageVersion>

Directory.Build.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<!-- Features in .NET 5.x, .NET 6.x, .NET 7.x, .NET 8.x, and .NET 9.x only -->
6464
<PropertyGroup Condition=" $(TargetFramework.StartsWith('net5.')) Or $(TargetFramework.StartsWith('net6.')) Or $(TargetFramework.StartsWith('net7.')) Or $(TargetFramework.StartsWith('net8.')) Or $(TargetFramework.StartsWith('net9.')) ">
6565

66+
<DefineConstants>$(DefineConstants);FEATURE_MEMORYMARSHAL_GETARRAYDATAREFERENCE</DefineConstants>
6667
<DefineConstants>$(DefineConstants);FEATURE_READONLYSET</DefineConstants>
6768

6869
</PropertyGroup>
@@ -91,6 +92,7 @@
9192
<DefineConstants>$(DefineConstants);FEATURE_ARRAY_FILL</DefineConstants>
9293
<DefineConstants>$(DefineConstants);FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR</DefineConstants>
9394
<DefineConstants>$(DefineConstants);FEATURE_CONDITIONALWEAKTABLE_ADDORUPDATE</DefineConstants>
95+
<DefineConstants>$(DefineConstants);FEATURE_MEMORYMARSHAL_CREATEREADONLYSPAN</DefineConstants>
9496
<DefineConstants>$(DefineConstants);FEATURE_NUMBER_PARSE_READONLYSPAN</DefineConstants>
9597
<DefineConstants>$(DefineConstants);FEATURE_STREAM_READ_SPAN</DefineConstants>
9698
<DefineConstants>$(DefineConstants);FEATURE_STRINGBUILDER_APPEND_READONLYSPAN</DefineConstants>

src/Lucene.Net.TestFramework/Support/TestFramework/Assert.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,18 @@ public static Exception Throws(Type expectedExceptionType, Action action, string
11641164
return _NUnit.Assert.Throws(expectedExceptionType, () => action(), message, args);
11651165
}
11661166

1167+
[DebuggerStepThrough]
1168+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1169+
public static T Throws<T>(string expectedParamName, Action action)
1170+
where T : ArgumentException
1171+
{
1172+
T exception = _NUnit.Assert.Throws<T>(() => action());
1173+
1174+
_NUnit.Assert.AreEqual(expectedParamName, exception.ParamName);
1175+
1176+
return exception;
1177+
}
1178+
11671179
[DebuggerStepThrough]
11681180
public static Exception ThrowsFileAlreadyExistsException(string filePath, Action action)
11691181
{

src/Lucene.Net.Tests._J-S/Lucene.Net.Tests._J-S.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<PropertyGroup>
2727
<AssemblyTitle>Lucene.Net.Tests._J-S</AssemblyTitle>
2828
<RootNamespace>Lucene.Net</RootNamespace>
29+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2930
</PropertyGroup>
3031

3132
<ItemGroup>

src/Lucene.Net.Tests._T-Z/Lucene.Net.Tests._T-Z.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
<PropertyGroup>
2727
<AssemblyTitle>Lucene.Net.Tests._T-Z</AssemblyTitle>
2828
<RootNamespace>Lucene.Net</RootNamespace>
29+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2930
</PropertyGroup>
3031

3132
<ItemGroup>
3233
<Compile Include="..\Lucene.Net.Tests\Properties\AssemblyInfo.cs" Link="Properties\AssemblyInfo.cs" />
3334
<Compile Include="..\Lucene.Net.Tests\Util\**\*.cs" LinkBase="Util" />
35+
<Compile Include="..\Lucene.Net.Tests\Support\TestHelpers.cs" />
3436
<Compile Remove="..\Lucene.Net.Tests\Util\JunitCompat\**\*;..\Lucene.Net.Tests\Util\TestMaxFailuresRule.cs" />
3537
</ItemGroup>
3638

0 commit comments

Comments
 (0)