Skip to content

Commit 49dc570

Browse files
author
Carl Burkert
committed
Use the optval function in the bitset routines
The optional advance argument leads to a redundant call of read/write routines which can be deduplicated by making use of the optval-function.
1 parent 53109cf commit 49dc570

File tree

3 files changed

+27
-64
lines changed

3 files changed

+27
-64
lines changed

src/stdlib_bitsets.fypp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module stdlib_bitsets
1313
int16, &
1414
int32, &
1515
int64
16+
use stdlib_optval, only : optval
1617

1718
use, intrinsic :: &
1819
iso_fortran_env, only: &

src/stdlib_bitsets_64.fypp

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -812,23 +812,13 @@ contains
812812
end if
813813
end do
814814

815-
if ( present(advance) ) then
816-
read( unit, &
817-
advance=advance, &
818-
FMT='(A1)', &
819-
err=997, &
820-
end=998, &
821-
iostat=ierr, &
822-
iomsg=message ) char
823-
else
824-
read( unit, &
825-
advance='YES', &
826-
FMT='(A1)', &
827-
err=997, &
828-
end=998, &
829-
iostat=ierr, &
830-
iomsg=message ) char
831-
end if
815+
read( unit, &
816+
advance=optval(advance, 'YES'), &
817+
FMT='(A1)', &
818+
err=997, &
819+
end=998, &
820+
iostat=ierr, &
821+
iomsg=message ) char
832822
if ( char == '0' ) then
833823
call self % clear( bits-bit )
834824
else if ( char == '1' ) then
@@ -1080,21 +1070,12 @@ contains
10801070
end if
10811071

10821072

1083-
if ( present( advance ) ) then
1084-
write( unit, &
1085-
FMT='(A)', &
1086-
advance=advance, &
1087-
iostat=ierr, &
1088-
iomsg=message ) &
1089-
string
1090-
else
1091-
write( unit, &
1092-
FMT='(A)', &
1093-
advance='YES', &
1094-
iostat=ierr, &
1095-
iomsg=message ) &
1096-
string
1097-
end if
1073+
write( unit, &
1074+
FMT='(A)', &
1075+
advance=optval(advance, 'YES'), &
1076+
iostat=ierr, &
1077+
iomsg=message ) &
1078+
string
10981079
if (ierr /= 0) then
10991080
call error_handler( 'Failure on a WRITE statement for UNIT.', &
11001081
write_failure, status, module_name, procedure )

src/stdlib_bitsets_large.fypp

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -997,23 +997,13 @@ contains
997997
end if
998998
end do
999999

1000-
if ( present(advance) ) then
1001-
read( unit, &
1002-
advance=advance, &
1003-
FMT='(A1)', &
1004-
err=997, &
1005-
end=998, &
1006-
iostat=ierr, &
1007-
iomsg=message ) char
1008-
else
1009-
read( unit, &
1010-
advance='YES', &
1011-
FMT='(A1)', &
1012-
err=997, &
1013-
end=998, &
1014-
iostat=ierr, &
1015-
iomsg=message ) char
1016-
end if
1000+
read( unit, &
1001+
advance=optval(advance, 'YES'), &
1002+
FMT='(A1)', &
1003+
err=997, &
1004+
end=998, &
1005+
iostat=ierr, &
1006+
iomsg=message ) char
10171007

10181008
if ( char == '0' ) then
10191009
call self % clear( bits-bit )
@@ -1302,21 +1292,12 @@ contains
13021292
end if
13031293

13041294

1305-
if ( present( advance ) ) then
1306-
write( unit, &
1307-
FMT='(A)', &
1308-
advance=advance, &
1309-
iostat=ierr, &
1310-
iomsg=message ) &
1311-
string
1312-
else
1313-
write( unit, &
1314-
FMT='(A)', &
1315-
advance='YES', &
1316-
iostat=ierr, &
1317-
iomsg=message ) &
1318-
string
1319-
end if
1295+
write( unit, &
1296+
FMT='(A)', &
1297+
advance=optval(advance, 'YES'), &
1298+
iostat=ierr, &
1299+
iomsg=message ) &
1300+
string
13201301
if (ierr /= 0) then
13211302
call error_handler( 'Failure on a WRITE statement for UNIT.', &
13221303
write_failure, status, module_name, procedure )

0 commit comments

Comments
 (0)