Wow.. Memoisation in XSLT! That's really great.
Mike, what exactly do you mean by "called twice with the same
arguments"?
For example, if the second time a corresponding argument is a
different node having the same string value (or which is
"deep equal" to the corresponding previous argument), will
this be "the same argument" ?
For atomic values, equal values. For nodes, the same node (by identity).
Now that params have types, I should be able to test the argument after
conversion to the target type, so if the param is type="xs:string", two
different nodes with the same string value would count as the same.
Is there any reason (besides performance (side-effects)) why
memoisation should not be the default behaviour?
I was worried about memory usage: to make it the default, I would have
to implement some kind of discard algorithm. Perhaps using a WeakHashMap
would be OK.
And I was a bit worried about side-effects. (a) Functions can call
extension functions that have side-effects, (b) Functions can create and
return new nodes.
Also I was concerned that for very simple functions, recomputing the
result is likely to be cheaper than managing the hash table.
Perhaps I was just being cautious, and wanted evidence that it worked
well before switching it on by default.
Michael Kay
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list