diff --git a/src/Hyperbee.Json/JsonPathBuilder.cs b/src/Hyperbee.Json/JsonPathBuilder.cs index 6a294c05..bd071195 100644 --- a/src/Hyperbee.Json/JsonPathBuilder.cs +++ b/src/Hyperbee.Json/JsonPathBuilder.cs @@ -1,6 +1,4 @@ -//#define USE_OPTIMIZED - -using System.Text.Json; +using System.Text.Json; namespace Hyperbee.Json; @@ -102,74 +100,6 @@ private static string BuildPath( int elementId, Dictionary(); - var parentMap = new Dictionary(); - var currentId = 0; - - stack.Push( (currentId, _rootElement) ); - parentMap[currentId] = (-1, "$"); - currentId++; - - while ( stack.Count > 0 ) - { - var (elementId, currentElement) = stack.Pop(); - - if ( _comparer.Equals( currentElement, targetElement ) ) - return BuildPath( elementId, parentMap ); - - switch ( currentElement.ValueKind ) - { - case JsonValueKind.Object: - foreach ( var property in currentElement.EnumerateObject() ) - { - var childElementId = currentId++; - parentMap[childElementId] = (elementId, $".{property.Name}"); - stack.Push( (childElementId, property.Value) ); - } - break; - - case JsonValueKind.Array: - var arrayIdx = 0; - foreach ( var element in currentElement.EnumerateArray() ) - { - var childElementId = currentId++; - parentMap[childElementId] = (elementId, $"[{arrayIdx}]"); - stack.Push( (childElementId, element) ); - arrayIdx++; - } - break; - } - } - - return null; // Target not found - } - - private static string BuildPath( int elementId, Dictionary parentMap ) - { - var pathSegments = new Stack(); - var currentId = elementId; - - while ( currentId != -1 ) - { - var (parentId, segment) = parentMap[currentId]; - pathSegments.Push( segment ); - currentId = parentId; - } - - return string.Join( string.Empty, pathSegments ); - } - -#else - // NAIVE IMPLEMENTATION public string GetPath( JsonElement targetElement ) @@ -209,7 +139,5 @@ public string GetPath( JsonElement targetElement ) return null; // Target no } - -#endif */ }