Skip to content

Commit d64ebd3

Browse files
committed
another reduction in list traversals when looping through an array.
added some additional comments.
1 parent de93579 commit d64ebd3

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/json_module.f90

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,7 +2511,8 @@ end subroutine json_value_get_by_index
25112511
!
25122512
! NOTES
25132513
! It is a case-sensitive search, and the name string is not trimmed,
2514-
! So, for example, 'a ' /= 'A ' /= 'a '
2514+
! So, for example, 'a ' /= 'A ' /= 'a '
2515+
! Note that the name is not parsed like it is in json_get_by_path.
25152516
!
25162517
! SOURCE
25172518

@@ -2523,7 +2524,7 @@ subroutine json_value_get_by_name_chars(this, name, p)
25232524
character(kind=CK,len=*),intent(in) :: name
25242525
type(json_value),pointer :: p
25252526

2526-
integer(IK) :: i
2527+
integer(IK) :: i,n_children
25272528

25282529
nullify(p)
25292530

@@ -2532,11 +2533,13 @@ subroutine json_value_get_by_name_chars(this, name, p)
25322533
if (associated(this)) then
25332534

25342535
if (this%var_type==json_object) then
2535-
do i=1, json_count(this)
2536-
call json_get_child(this, i, p)
2536+
n_children = json_count(this)
2537+
p => this%children !start with first one
2538+
do i=1, n_children
25372539
if (allocated(p%name)) then
25382540
if (p%name == name) return
25392541
end if
2542+
p => p%next
25402543
end do
25412544
end if
25422545

@@ -2924,19 +2927,23 @@ end subroutine json_value_print
29242927
! DESCRIPTION
29252928
! Returns the json_value pointer given the path string.
29262929
!
2927-
! NOTES
2928-
! Path syntax is:
2929-
! $ root
2930-
! @ this
2931-
! . child object member
2932-
! [] or () child array element
2933-
!
29342930
! EXAMPLE
29352931
! type(json_value),pointer :: dat,p
29362932
! logical :: found
29372933
! ...
29382934
! call json_get(dat,'data(2).version',p,found)
29392935
!
2936+
! NOTES
2937+
! The following special characters are used to denote paths:
2938+
! $ - root
2939+
! @ - this
2940+
! . - child object member
2941+
! [] or () - child array element
2942+
!
2943+
! Thus, if any of these characters are present in the name key,
2944+
! this routine cannot be used to get the value.
2945+
! In that case, the json_get_child routines would need to be used.
2946+
!
29402947
! SOURCE
29412948

29422949
subroutine json_get_by_path(this, path, p, found)

0 commit comments

Comments
 (0)