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:
parent
735c06d7f1
commit
5a43a20f53
1 changed files with 2 additions and 2 deletions
|
|
@ -209,7 +209,7 @@ proc toLowerAscii*(c: char): char {.noSideEffect,
|
||||||
doAssert toLowerAscii('A') == 'a'
|
doAssert toLowerAscii('A') == 'a'
|
||||||
doAssert toLowerAscii('e') == 'e'
|
doAssert toLowerAscii('e') == 'e'
|
||||||
if c in {'A'..'Z'}:
|
if c in {'A'..'Z'}:
|
||||||
result = chr(ord(c) + (ord('a') - ord('A')))
|
result = char(uint8(c) xor 0b0010_0000'u8)
|
||||||
else:
|
else:
|
||||||
result = c
|
result = c
|
||||||
|
|
||||||
|
|
@ -248,7 +248,7 @@ proc toUpperAscii*(c: char): char {.noSideEffect,
|
||||||
doAssert toUpperAscii('a') == 'A'
|
doAssert toUpperAscii('a') == 'A'
|
||||||
doAssert toUpperAscii('E') == 'E'
|
doAssert toUpperAscii('E') == 'E'
|
||||||
if c in {'a'..'z'}:
|
if c in {'a'..'z'}:
|
||||||
result = chr(ord(c) - (ord('a') - ord('A')))
|
result = char(uint8(c) xor 0b0010_0000'u8)
|
||||||
else:
|
else:
|
||||||
result = c
|
result = c
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue