mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-06 11:54:11 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user