11using System ;
2- using System . Diagnostics ;
32using System . Text ;
4- using System . Threading ;
53using BenchmarkDotNet . Attributes ;
64using BenchmarkDotNet . Attributes . Exporters ;
75using BenchmarkDotNet . Attributes . Jobs ;
@@ -22,7 +20,7 @@ public class LinkBuilder_GetNamespaceFromPath_Benchmarks
2220 public void UsingSpanWithStringBuilder ( ) => GetNamespaceFromPath_Using_Span_With_StringBuilder ( PATH , ENTITY_NAME ) ;
2321
2422 [ Benchmark ]
25- public void UsingSpanWithNoAlloc ( ) => GetNamespaceFromPath_Using_Span_No_Alloc ( PATH , ENTITY_NAME ) ;
23+ public void Current ( ) => GetNameSpaceFromPath_Current ( PATH , ENTITY_NAME ) ;
2624
2725 public static string GetNamespaceFromPath_BySplitting ( string path , string entityName )
2826 {
@@ -40,36 +38,8 @@ public static string GetNamespaceFromPath_BySplitting(string path, string entity
4038 return nSpace ;
4139 }
4240
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 ) ;
7343
7444 public static string GetNamespaceFromPath_Using_Span_With_StringBuilder ( string path , string entityName )
7545 {
0 commit comments