summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBung <crc32@qq.com>2020-12-01 01:24:12 +0800
committerGitHub <noreply@github.com>2020-11-30 18:24:12 +0100
commit5a43a20f53d826e5f5e47ca49aa7423fd9cba21b (patch)
tree7b11aeb6f15e0ab48c47dd2277f1434c98b9f468
parent735c06d7f12ee3e4733754f57a1710e9d0dba5d9 (diff)
downloadNim-5a43a20f53d826e5f5e47ca49aa7423fd9cba21b.tar.gz
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>
-rw-r--r--lib/pure/strutils.nim4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index f0b447de7..8cbc947bf 100644
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -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