summary refs log tree commit diff stats
path: root/lib/packages
diff options
context:
space:
mode:
authorDmitry Atamanov <data-man@users.noreply.github.com>2018-05-25 00:04:30 +0300
committerGitHub <noreply@github.com>2018-05-25 00:04:30 +0300
commite206a8d95240e766474d601f529fef1c0026f80f (patch)
treeefd87a5f80850612bfc9f956536e3ecfa9ed4afb /lib/packages
parent85b7d8fcc4032a0d95af3f25faf1cc850f7d59f5 (diff)
downloadNim-e206a8d95240e766474d601f529fef1c0026f80f.tar.gz
Use new binarySearch everywhere (#7876)
Diffstat (limited to 'lib/packages')
-rw-r--r--lib/packages/docutils/highlite.nim27
1 files changed, 3 insertions, 24 deletions
diff --git a/lib/packages/docutils/highlite.nim b/lib/packages/docutils/highlite.nim
index 2a58854a6..4f1264c9e 100644
--- a/lib/packages/docutils/highlite.nim
+++ b/lib/packages/docutils/highlite.nim
@@ -13,6 +13,7 @@
 
 import
   strutils
+from algorithm import binarySearch
 
 type
   TokenClass* = enum
@@ -365,32 +366,10 @@ proc generalStrLit(g: var GeneralTokenizer, position: int): int =
   result = pos
 
 proc isKeyword(x: openArray[string], y: string): int =
-  var a = 0
-  var b = len(x) - 1
-  while a <= b:
-    var mid = (a + b) div 2
-    var c = cmp(x[mid], y)
-    if c < 0:
-      a = mid + 1
-    elif c > 0:
-      b = mid - 1
-    else:
-      return mid
-  result = - 1
+  binarySearch(x, y)
 
 proc isKeywordIgnoreCase(x: openArray[string], y: string): int =
-  var a = 0
-  var b = len(x) - 1
-  while a <= b:
-    var mid = (a + b) div 2
-    var c = cmpIgnoreCase(x[mid], y)
-    if c < 0:
-      a = mid + 1
-    elif c > 0:
-      b = mid - 1
-    else:
-      return mid
-  result = - 1
+  binarySearch(x, y, cmpIgnoreCase)
 
 type
   TokenizerFlag = enum