Skip to content

Commit

Permalink
Updated code formatting to match rules in .editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jun 10, 2024
1 parent b80b917 commit 621d785
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class JsonPathElementFunction<TType>( ParseExpressionContext<TType> conte
protected override Expression Evaluate( ReadOnlySpan<char> data, ReadOnlySpan<char> item, ref int start, ref int from )
{
var queryExp = Expression.Constant( item.ToString() );

// Create a call expression for the extension method
return Expression.Call( JsonPathHelper<TType>.GetFirstElementValueMethod, context.Current, context.Root, queryExp );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ static JsonPathHelper()
{
var thisType = typeof( JsonPathHelper<TType> );

GetFirstElementValueMethod = thisType.GetMethod( nameof( GetFirstElementValue ), [typeof( TType ), typeof( TType ), typeof( string ) ] );
GetFirstElementMethod = thisType.GetMethod( nameof( GetFirstElement ), [typeof( TType ), typeof( TType ), typeof( string ) ] );
SelectMethod = thisType.GetMethod( nameof( Select ), [typeof( TType ), typeof( TType ), typeof( string ) ] );
GetFirstElementValueMethod = thisType.GetMethod( nameof( GetFirstElementValue ), [typeof( TType ), typeof( TType ), typeof( string )] );
GetFirstElementMethod = thisType.GetMethod( nameof( GetFirstElement ), [typeof( TType ), typeof( TType ), typeof( string )] );
SelectMethod = thisType.GetMethod( nameof( Select ), [typeof( TType ), typeof( TType ), typeof( string )] );

IsTruthyMethod = thisType.GetMethod( nameof( IsTruthy ) );
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public static object GetFirstElementValue( JsonNode current, JsonNode root, stri
}

//BF: SelectFirst ? Is visitor optimized for first ? Could these be moved out to just use the extensions ?

public static JsonElement GetFirstElement( JsonElement current, JsonElement root, string query )
{
return new JsonPath()
Expand Down
6 changes: 3 additions & 3 deletions src/Hyperbee.Json/JsonElementInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Hyperbee.Json;

internal static class JsonElementInternal
{
internal static readonly Func<JsonElement, int> GetIdx;
internal static readonly Func<JsonElement, int> GetIdx;
internal static readonly Func<JsonElement, JsonDocument> GetParent;

static JsonElementInternal()
Expand All @@ -18,7 +18,7 @@ static JsonElementInternal()
if ( idxField == null )
throw new MissingFieldException( nameof( JsonElement ), "_idx" );

var getIdxDynamicMethod = new DynamicMethod( nameof(GetIdx), typeof( int ), [typeof( JsonElement )], typeof( JsonElement ) );
var getIdxDynamicMethod = new DynamicMethod( nameof( GetIdx ), typeof( int ), [typeof( JsonElement )], typeof( JsonElement ) );
var ilIdx = getIdxDynamicMethod.GetILGenerator();
ilIdx.Emit( OpCodes.Ldarg_0 );
ilIdx.Emit( OpCodes.Ldfld, idxField );
Expand All @@ -33,7 +33,7 @@ static JsonElementInternal()
if ( parentField == null )
throw new MissingFieldException( nameof( JsonElement ), "_parent" );

var getParentDynamicMethod = new DynamicMethod( nameof(GetParent), typeof( JsonDocument ), [typeof( JsonElement )], typeof( JsonElement ) );
var getParentDynamicMethod = new DynamicMethod( nameof( GetParent ), typeof( JsonDocument ), [typeof( JsonElement )], typeof( JsonElement ) );
var ilParent = getParentDynamicMethod.GetILGenerator();
ilParent.Emit( OpCodes.Ldarg_0 );
ilParent.Emit( OpCodes.Ldfld, parentField );
Expand Down
2 changes: 1 addition & 1 deletion src/Hyperbee.Json/JsonElementPositionComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public bool Equals( JsonElement x, JsonElement y )
//
// These arguments are stored in private fields and are not exposed. While note ideal, we
// will access these fields through dynamic methods to use for our comparison.

// check parent documents

// BF: JsonElement ctor notes that parent may be null in some enumeration conditions.
Expand Down
2 changes: 1 addition & 1 deletion src/Hyperbee.Json/JsonPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Hyperbee.Json;
public sealed class JsonPath
{
public static IJsonPathFilterEvaluator<JsonElement> FilterEvaluator { get; set; } = new JsonPathExpressionEvaluator<JsonElement>();

private readonly JsonPathVisitorBase<JsonElement> _visitor = new JsonPathElementVisitor();

public IEnumerable<JsonElement> Select( in JsonElement value, string query )
Expand Down
4 changes: 2 additions & 2 deletions src/Hyperbee.Json/JsonPathBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json;
using System.Text.Json;

namespace Hyperbee.Json;

Expand Down Expand Up @@ -79,7 +79,7 @@ public string GetPath( JsonElement targetElement )

private static int GetUniqueId( JsonElement element )
{
return JsonElementInternal.GetIdx( element );
return JsonElementInternal.GetIdx( element );
}

private static string BuildPath( int elementId, Dictionary<int, (int parentId, string segment)> parentMap )
Expand Down
24 changes: 12 additions & 12 deletions src/Hyperbee.Json/JsonPathVisitorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public abstract class JsonPathVisitorBase<TElement>
internal IEnumerable<TElement> ExpressionVisitor( in TElement value, in TElement root, string query, IJsonPathFilterEvaluator<TElement> filterEvaluator )
{
if ( string.IsNullOrWhiteSpace( query ) )
throw new ArgumentNullException( nameof(query) );
throw new ArgumentNullException( nameof( query ) );

if ( filterEvaluator == null )
throw new ArgumentNullException( nameof(filterEvaluator) );
throw new ArgumentNullException( nameof( filterEvaluator ) );

// quick out

if ( query == "$" )
Expand All @@ -65,14 +65,14 @@ internal IEnumerable<TElement> ExpressionVisitor( in TElement value, in TElement
if ( !tokens.IsEmpty )
{
var selector = tokens.Peek().FirstSelector;

if ( selector == "$" || selector == "@" )
tokens = tokens.Pop();
}

return ExpressionVisitor( root, new VisitorArgs( value, tokens ), filterEvaluator );
}

private IEnumerable<TElement> ExpressionVisitor( TElement root, VisitorArgs args, IJsonPathFilterEvaluator<TElement> filterEvaluator )
{
var stack = new Stack<VisitorArgs>( 4 );
Expand Down Expand Up @@ -115,7 +115,7 @@ private IEnumerable<TElement> ExpressionVisitor( TElement root, VisitorArgs args
{
foreach ( var (_, childKey) in EnumerateChildValues( current ) )
{
Push( stack, current, tokens.Push( new ( childKey, SelectorKind.UnspecifiedSingular ) ) ); // (Dot | Index)
Push( stack, current, tokens.Push( new( childKey, SelectorKind.UnspecifiedSingular ) ) ); // (Dot | Index)
}

continue;
Expand All @@ -128,19 +128,19 @@ private IEnumerable<TElement> ExpressionVisitor( TElement root, VisitorArgs args
foreach ( var (childValue, _) in EnumerateChildValues( current ) )
{
if ( IsObjectOrArray( childValue ) )
Push( stack, childValue, tokens.Push( new ( "..", SelectorKind.UnspecifiedGroup ) ) ); // Descendant
Push( stack, childValue, tokens.Push( new( "..", SelectorKind.UnspecifiedGroup ) ) ); // Descendant
}

Push( stack, current, tokens );
continue;
}

// union

for ( var i = 0; i < token.Selectors.Length; i++ ) // using 'for' for performance
{
var childSelector = token.Selectors[i].Value;

// [(exp)]

if ( childSelector.Length > 2 && childSelector[0] == '(' && childSelector[^1] == ')' )
Expand All @@ -152,7 +152,7 @@ private IEnumerable<TElement> ExpressionVisitor( TElement root, VisitorArgs args
? SelectorKind.UnspecifiedSingular
: SelectorKind.UnspecifiedGroup;

Push( stack, current, tokens.Push( new ( evalSelector, selectorKind ) ) );
Push( stack, current, tokens.Push( new( evalSelector, selectorKind ) ) );
continue;
}

Expand All @@ -166,7 +166,7 @@ private IEnumerable<TElement> ExpressionVisitor( TElement root, VisitorArgs args

// treat the filter result as truthy if the evaluator returned a non-convertible object instance.
if ( filter is not null and not IConvertible || Convert.ToBoolean( filter, CultureInfo.InvariantCulture ) )
Push( stack, current, tokens.Push( new ( childKey, SelectorKind.UnspecifiedSingular ) ) ); // (Name | Index)
Push( stack, current, tokens.Push( new( childKey, SelectorKind.UnspecifiedSingular ) ) ); // (Name | Index)
}

continue;
Expand All @@ -193,7 +193,7 @@ private IEnumerable<TElement> ExpressionVisitor( TElement root, VisitorArgs args

// [name1,name2,...]
foreach ( var index in EnumerateArrayIndices( length ) )
Push( stack, GetElementAt( current, index ), tokens.Push( new ( childSelector, SelectorKind.UnspecifiedSingular ) ) ); // Name
Push( stack, GetElementAt( current, index ), tokens.Push( new( childSelector, SelectorKind.UnspecifiedSingular ) ) ); // Name

continue;
}
Expand Down
4 changes: 2 additions & 2 deletions test/Hyperbee.Json.Benchmark/JsonPathExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public void Setup()
{
_nodeExpressionContext = new ParseExpressionContext<JsonNode>(
Expression.Parameter( typeof( JsonNode ) ),
Expression.Parameter( typeof( JsonNode ) ) );
Expression.Parameter( typeof( JsonNode ) ) );

_elementExpressionContext = new ParseExpressionContext<JsonElement>(
Expression.Parameter( typeof( JsonElement ) ),
Expression.Parameter( typeof( JsonElement ) ) );
Expression.Parameter( typeof( JsonElement ) ) );
}

[Benchmark]
Expand Down

0 comments on commit 621d785

Please sign in to comment.