diff options
author | cooldome <ariabushenko@gmail.com> | 2020-11-03 15:26:16 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-03 16:26:16 +0100 |
commit | d62f3627aa1946cd5fa9d3e52abedf9576db0e8e (patch) | |
tree | f9b00ce58afd799ad3ab3f1e8b7bb2a7e232dc7e /compiler/wordrecg.nim | |
parent | b8bcf236dd29ee2a6ec7587dc3f028f14023ebec (diff) | |
download | Nim-d62f3627aa1946cd5fa9d3e52abedf9576db0e8e.tar.gz |
EnumUtils, speed up findStr in compiler (#15777)
* add parseEnumRange * fix runnable example * update changelog * use parseEnumRange in compiler * reorganise code * add changelog, make single normalizer argument
Diffstat (limited to 'compiler/wordrecg.nim')
-rw-r--r-- | compiler/wordrecg.nim | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim index e2e3a1d2f..170d04df1 100644 --- a/compiler/wordrecg.nim +++ b/compiler/wordrecg.nim @@ -13,8 +13,6 @@ # does not support strings. Without this the code would # be slow and unreadable. -from strutils import cmpIgnoreStyle - type TSpecialWord* = enum wInvalid = "", @@ -125,8 +123,21 @@ const wAsm, wBreak, wCase, wConst, wContinue, wDo, wElse, wEnum, wExport, wFor, wIf, wReturn, wStatic, wTemplate, wTry, wWhile, wUsing} -proc findStr*[T:enum](a: Slice[T], s: string, default: T): T = - for i in a: - if cmpIgnoreStyle($i, s) == 0: - return i - result = default \ No newline at end of file + +const enumUtilsExist = compiles: + import std/enumutils + +when enumUtilsExist: + from std/enumutils import genEnumCaseStmt + from strutils import normalize + proc findStr*[T: enum](a, b: static[T], s: string, default: T): T = + genEnumCaseStmt(T, s, default, ord(a), ord(b), normalize) + +else: + from strutils import cmpIgnoreStyle + proc findStr*[T: enum](a, b: static[T], s: string, default: T): T {.deprecated.} = + # used for compiler bootstrapping only + for i in a..b: + if cmpIgnoreStyle($i, s) == 0: + return i + result = default \ No newline at end of file |