From b1a369d2fbb89112d90e54a34f94d4aae1bd1bc6 Mon Sep 17 00:00:00 2001 From: Zajcev Evgeny Date: Mon, 7 Nov 2016 13:21:17 +0300 Subject: [PATCH] [enh] isUpperAscii*, isLowerAscii* speedup execution by stopping iteration as soon as possible --- lib/pure/strutils.nim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index bfc32bc71d..129869373d 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -179,9 +179,10 @@ proc isLowerAscii*(s: string): bool {.noSideEffect, procvar, if s.len() == 0: return false - result = true for c in s: - result = c.isLowerAscii() and result + if not c.isLowerAscii(): + return false + true proc isUpperAscii*(s: string): bool {.noSideEffect, procvar, rtl, extern: "nsuIsUpperAsciiStr".}= @@ -193,9 +194,10 @@ proc isUpperAscii*(s: string): bool {.noSideEffect, procvar, if s.len() == 0: return false - result = true for c in s: - result = c.isUpperAscii() and result + if not c.isUpperAscii(): + return false + true proc toLowerAscii*(c: char): char {.noSideEffect, procvar, rtl, extern: "nsuToLowerAsciiChar".} =