Skip to content

Commit

Permalink
Merge branch 'feature/6-feature-use-expressions-for-filters' of https…
Browse files Browse the repository at this point in the history
…://github.com/Stillpoint-Software/hyperbee.json into feature/6-feature-use-expressions-for-filters
  • Loading branch information
MattEdwardsWaggleBee committed Jun 11, 2024
2 parents a846f7d + 559687c commit cc46d7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/Hyperbee.Json/JsonPathBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public JsonPathBuilder( JsonElement rootElement )
{
_rootElement = rootElement;

// we will avoid allocating full paths for every node by
// building a dictionary cache of (parentId, segment) pairs.
// avoid allocating full paths for every node by building
// a dictionary of (parentId, segment) pairs.

_parentMap[GetUniqueId( _rootElement )] = (-1, "$"); // seed parent map with root
}

public string GetPath( JsonElement targetElement )
public string GetPath( in JsonElement targetElement )
{
// quick out

Expand Down Expand Up @@ -77,12 +77,12 @@ public string GetPath( JsonElement targetElement )
return null; // target not found
}

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

private static string BuildPath( int elementId, Dictionary<int, (int parentId, string segment)> parentMap )
private static string BuildPath( in int elementId, Dictionary<int, (int parentId, string segment)> parentMap )
{
var pathSegments = new Stack<string>();
var currentId = elementId;
Expand Down
14 changes: 9 additions & 5 deletions src/Hyperbee.Json/Tokenizer/JsonPathToken.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace Hyperbee.Json.Tokenizer;

Expand All @@ -20,16 +21,19 @@ internal record JsonPathToken

public bool Singular
{
[MethodImpl( MethodImplOptions.AggressiveInlining )]
get
{
if ( Selectors.Length != 1 )
return false;

return Selectors[0].SelectorKind == SelectorKind.UnspecifiedSingular || // prioritize runtime value
Selectors[0].SelectorKind == SelectorKind.Dot ||
Selectors[0].SelectorKind == SelectorKind.Index ||
Selectors[0].SelectorKind == SelectorKind.Name ||
Selectors[0].SelectorKind == SelectorKind.Root;
var selectorKind = Selectors[0].SelectorKind;

return selectorKind == SelectorKind.UnspecifiedSingular || // prioritize runtime value
selectorKind == SelectorKind.Dot ||
selectorKind == SelectorKind.Index ||
selectorKind == SelectorKind.Name ||
selectorKind == SelectorKind.Root;
}
}

Expand Down

0 comments on commit cc46d7e

Please sign in to comment.