From 5a43a20f53d826e5f5e47ca49aa7423fd9cba21b Mon Sep 17 00:00:00 2001 From: Bung Date: Tue, 1 Dec 2020 01:24:12 +0800 Subject: [PATCH] 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 Co-authored-by: hlaaftana <10591326+hlaaftana@users.noreply.github.com> --- lib/pure/strutils.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index f0b447de79..8cbc947bf8 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