toXXAscii use xor op, saving 30%~50% time (#16193)

* toXXAscii use xor op, saving 30%~50% time

* Update lib/pure/strutils.nim

Co-authored-by: hlaaftana <10591326+hlaaftana@users.noreply.github.com>

* Update lib/pure/strutils.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Co-authored-by: hlaaftana <10591326+hlaaftana@users.noreply.github.com>
This commit is contained in:
Bung
2020-12-01 01:24:12 +08:00
committed by GitHub
parent 735c06d7f1
commit 5a43a20f53

View File

@@ -209,7 +209,7 @@ proc toLowerAscii*(c: char): char {.noSideEffect,
doAssert toLowerAscii('A') == 'a'
doAssert toLowerAscii('e') == 'e'
if c in {'A'..'Z'}:
result = chr(ord(c) + (ord('a') - ord('A')))
result = char(uint8(c) xor 0b0010_0000'u8)
else:
result = c
@@ -248,7 +248,7 @@ proc toUpperAscii*(c: char): char {.noSideEffect,
doAssert toUpperAscii('a') == 'A'
doAssert toUpperAscii('E') == 'E'
if c in {'a'..'z'}:
result = chr(ord(c) - (ord('a') - ord('A')))
result = char(uint8(c) xor 0b0010_0000'u8)
else:
result = c