summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorFlaviu Tamas <tamasflaviu@gmail.com>2018-10-28 00:52:49 -0400
committerFlaviu Tamas <tamasflaviu@gmail.com>2018-10-28 00:53:09 -0400
commit9ca1c2c93035341e06d85f56edeb6a08f962a9e8 (patch)
treeb148956f5631c482ea7425abdb17f933305cf1d8 /lib
parentf2cd8ed99a7caa00b20bae2443cacf2d97700d75 (diff)
downloadNim-9ca1c2c93035341e06d85f56edeb6a08f962a9e8.tar.gz
Eliminate floating point arithmatic in nre
Integer division is already hard enough on your CPU, using floating
point here is WAY slower and can just as effectivly be done using
integers. This is important because matchImpl tends to be in the center
of very hot loops (like split()).
Diffstat (limited to 'lib')
-rw-r--r--lib/impure/nre.nim3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/impure/nre.nim b/lib/impure/nre.nim
index ce3fb2aff..5155194b0 100644
--- a/lib/impure/nre.nim
+++ b/lib/impure/nre.nim
@@ -469,7 +469,8 @@ proc matchImpl(str: string, pattern: Regex, start, endpos: int, flags: int): Opt
   # 1x capture count as slack space for PCRE
   let vecsize = (pattern.captureCount() + 1) * 3
   # div 2 because each element is 2 cints long
-  myResult.pcreMatchBounds = newSeq[HSlice[cint, cint]](ceil(vecsize / 2).int)
+  # plus 1 because we need the ceiling, not the floor
+  myResult.pcreMatchBounds = newSeq[HSlice[cint, cint]]((vecsize div 2) + 1)
   myResult.pcreMatchBounds.setLen(vecsize div 3)
 
   let strlen = if endpos == int.high: str.len else: endpos+1