[ performance ] improve some Char functions (#2839)

This commit is contained in:
Stefan Höck 2023-01-06 10:08:38 +01:00 committed by GitHub
parent f9dc56a5f4
commit 8db12f5a49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 11 deletions

View File

@ -53,6 +53,10 @@
### Library changes
#### Prelude
* Improved performance of functions `isNL`, `isSpace`, and `isHexDigit`.
#### Base
* Deprecates `setByte` and `getByte` from `Data.Buffer` for removal in a future

View File

@ -915,15 +915,21 @@ isAlphaNum x = isDigit x || isAlpha x
||| Returns true if the character is a whitespace character.
public export
isSpace : Char -> Bool
isSpace x
= x == ' ' || x == '\t' || x == '\r' ||
x == '\n' || x == '\f' || x == '\v' ||
x == '\xa0'
isSpace ' ' = True
isSpace '\t' = True
isSpace '\r' = True
isSpace '\n' = True
isSpace '\f' = True
isSpace '\v' = True
isSpace '\xa0' = True
isSpace _ = False
||| Returns true if the character represents a new line.
public export
isNL : Char -> Bool
isNL x = x == '\r' || x == '\n'
isNL '\r' = True
isNL '\n' = True
isNL _ = False
||| Convert a letter to the corresponding upper-case letter, if any.
||| Non-letters are ignored.
@ -947,11 +953,7 @@ toLower x
||| [0-9][a-f][A-F].
public export
isHexDigit : Char -> Bool
isHexDigit x = elem (toUpper x) hexChars where
hexChars : List Char
hexChars
= ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F']
isHexDigit x = isDigit x || ('a' <= x && x <= 'f') || ('A' <= x && x <= 'F')
||| Returns true if the character is an octal digit.
public export

View File

@ -12,6 +12,6 @@ LOG declare.record.parameters:50: Decided to bind the following extra parameters
LOG declare.record.parameters:60: We elaborated Main.EtaProof in a non-empty local context.
Dropped: [b, a]
Remaining type: (p : ($resolved2673 a[1] b[0])) -> Type
Remaining type: (p : ($resolved2672 a[1] b[0])) -> Type
LOG declare.record.parameters:30: Unelaborated type: (%pi RigW Explicit Nothing Main.Product %type)