Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faster to_lower and to_upper #733

Merged
merged 8 commits into from
Oct 13, 2023
14 changes: 10 additions & 4 deletions src/stdlib_ascii.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,13 @@ contains
pure function to_lower(string) result(lower_string)
character(len=*), intent(in) :: string
character(len=len(string)) :: lower_string
integer :: i
integer, parameter :: wp= 32, la=65, lz= 90
integer :: i, icar

do i = 1, len(string)
lower_string(i:i) = char_to_lower(string(i:i))
icar= ichar(string(i:i))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you not modify char_to_lower instead of each occurence?

if (icar>=la.and.icar<=lz) icar= icar + wp
lower_string(i:i) = char(icar)
end do

end function to_lower
Expand All @@ -272,10 +275,13 @@ contains
pure function to_upper(string) result(upper_string)
character(len=*), intent(in) :: string
character(len=len(string)) :: upper_string
integer :: i
integer, parameter :: wp= 32, BA=97, BZ= 122
integer :: i, icar

do i = 1, len(string)
upper_string(i:i) = char_to_upper(string(i:i))
icar= ichar(string(i:i))
if (icar>=BA.and.icar<=BZ) icar= icar - wp
upper_string(i:i) = char(icar)
end do

end function to_upper
Expand Down