1
1
using System ;
2
- using System . Diagnostics ;
3
2
using System . Text ;
4
- using System . Threading ;
5
3
using BenchmarkDotNet . Attributes ;
6
4
using BenchmarkDotNet . Attributes . Exporters ;
7
5
using BenchmarkDotNet . Attributes . Jobs ;
@@ -22,7 +20,7 @@ public class LinkBuilder_GetNamespaceFromPath_Benchmarks
22
20
public void UsingSpanWithStringBuilder ( ) => GetNamespaceFromPath_Using_Span_With_StringBuilder ( PATH , ENTITY_NAME ) ;
23
21
24
22
[ Benchmark ]
25
- public void UsingSpanWithNoAlloc ( ) => GetNamespaceFromPath_Using_Span_No_Alloc ( PATH , ENTITY_NAME ) ;
23
+ public void Current ( ) => GetNameSpaceFromPath_Current ( PATH , ENTITY_NAME ) ;
26
24
27
25
public static string GetNamespaceFromPath_BySplitting ( string path , string entityName )
28
26
{
@@ -40,36 +38,8 @@ public static string GetNamespaceFromPath_BySplitting(string path, string entity
40
38
return nSpace ;
41
39
}
42
40
43
- public static string GetNamespaceFromPath_Using_Span_No_Alloc ( string path , string entityName )
44
- {
45
- var entityNameSpan = entityName . AsSpan ( ) ;
46
- var pathSpan = path . AsSpan ( ) ;
47
- const char delimiter = '/' ;
48
- for ( var i = 0 ; i < pathSpan . Length ; i ++ )
49
- {
50
- if ( pathSpan [ i ] . Equals ( delimiter ) )
51
- {
52
- var nextPosition = i + 1 ;
53
- if ( pathSpan . Length > i + entityNameSpan . Length )
54
- {
55
- var possiblePathSegment = pathSpan . Slice ( nextPosition , entityNameSpan . Length ) ;
56
- if ( entityNameSpan . SequenceEqual ( possiblePathSegment ) )
57
- {
58
- // check to see if it's the last position in the string
59
- // or if the next character is a /
60
- var lastCharacterPosition = nextPosition + entityNameSpan . Length ;
61
-
62
- if ( lastCharacterPosition == pathSpan . Length || pathSpan . Length >= lastCharacterPosition + 2 && pathSpan [ lastCharacterPosition + 1 ] . Equals ( delimiter ) )
63
- {
64
- return pathSpan . Slice ( 0 , i ) . ToString ( ) ;
65
- }
66
- }
67
- }
68
- }
69
- }
70
-
71
- return string . Empty ;
72
- }
41
+ public static string GetNameSpaceFromPath_Current ( string path , string entityName )
42
+ => JsonApiDotNetCore . Builders . LinkBuilder . GetNamespaceFromPath ( path , entityName ) ;
73
43
74
44
public static string GetNamespaceFromPath_Using_Span_With_StringBuilder ( string path , string entityName )
75
45
{
0 commit comments