Trust-Machines / BNS-V2

MIT License
10 stars 3 forks source link

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

Open FriendsFerdinand opened 1 month ago

FriendsFerdinand commented 1 month ago

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 commented 1 month ago

Thanks, will look into this