-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Splitting with empty string as separator causes high memory usage #4
Comments
This is really weird, because the split symbol can be used with an empty separator in min: ...but in mn it hangs. The annoying thing is that the implementation is essentially the same, but perhaps in min if the pcre library is included the behavior changes. Perhaps the easiest thing would be to handle this as a special case in mn and if the separator is an empty string try to use something else in Nim to split the string, maybe create a sequence via an iterator or something. |
Seems like Nim problem. I have written a simple program to test my suggestion: import
strutils
proc main =
var i = 0
echo "hello".split("") ## compiles, but assertion (sep.len > 0) error at runtime
#but
for e in "hello".split(""): ## infinite loop
i.inc
echo i ## to confirm that something happens
echo e
main() Possible solution: def.symbol("split") do (i: In):
let vals = i.expect("'sym", "'sym")
let sep = vals[0].getString
let s = vals[1].getString
var q = newSeq[MnValue](0)
if sep.len > 0:
for e in s.split(sep):
q.add e.newVal
else:
for e in s:
q.add e.newVal
i.push q.newVal |
Fixed on master 😊👍 |
causes high memory usage and heavy swapping, so that PC sometimes even freezes (Windows 10 x64, 8 GB RAM)
My intention was to get separate characters, but according to nim's
split
documentation, with empty separator nim'ssplit
returns unmodified string. Somehowsplit
in mn does neither.The text was updated successfully, but these errors were encountered: