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

Replace is-lowercase-alpha and is-digit individual checks for a range check #63

Open
FriendsFerdinand opened this issue Jul 10, 2024 · 1 comment

Comments

@FriendsFerdinand
Copy link
Collaborator

FriendsFerdinand commented Jul 10, 2024

Currently is-lowercase-alpha and is-digit compares char individually with each different case. We can replace this with a range check like this:

;; Determines if a character is a digit (0-9).
(define-private (is-digit-test (char (buff 1)))
    (and
        ;; Checks if the character is between '0' and '9' using hex values.
        (>= char 0x30) ;; 0
        (<= char 0x39) ;; 9
    )
) 

;; Checks if a character is a lowercase alphabetic character (a-z).
(define-read-only (is-lowercase-alpha-test (char (buff 1)))
    (and
        ;; Checks for each lowercase letter using hex values.
        (>= char 0x61) ;; a
        (<= char 0x7a) ;; z
    )
)

Further, we could use inequality <,> and increase/lower by 1 the ranges and optimize even further but at the risk of reducing clarity.

@Patotking12
Copy link
Collaborator

Thanks, will look into this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants