Hi all,
(Referring to "PolyML 5.5.0 release")
I am trying to copy the initial part of an array into another array, something like OCamls: "Array.blit src 0 dst 0 len"
In PolyML, I have Array.copy, that copies the whole array, i.e., fixes len=length src, which is to restrictive for my purpose.
I can solve my problem with "ArraySlice.copy {src=ArraySlice.slice(src,0,SOME len),di=0,dst=dst}"
However, this solution has very poor performance. Looking at the code, it becomes clear why: Array.copy is implemented natively by "move_words", however, ArraySlice.copy is implemented as a recursive function inside ML. This is a performance difference of roughly two orders of magnitude!
There is a comment on ArraySlice.copy that "We can't use System_move_words because of the potential overlap problem."
However, looking at the implementations of move_words, I find:
x86asm.asm: ;# Must deal with the case of overlapping segments correctly. (which the implementation there does)
run_time.cpp: memmove(dest, source, words*sizeof(PolyWord)); /* must work for overlapping segments. */ (which it does according to C++ specification)
Nevertheless, a quick test reveals that System_move_words does not work for overlapping memory! What am I missing?
So, this results in a few questions: 1) Is there a fast solution two my problem within the SML-standard, where I can even assume that src and dst are different arrays?
2) Can ArraySlice.copy be patched to use System_move_words after a check that the arrays are actually not the same?
3) Where is the code executed by System_move_words, and can this be fixed to correctly handle overlapping segments?
Best, Peter