[m-rev.] for review: string switches using tries

Zoltan Somogyi zoltan.somogyi at runbox.com
Mon Feb 23 16:01:54 AEDT 2015


For review by anyone.

We discussed this recently, and I found a way to implement it
that should work for non-C backends. At each tip of the trie,
where there is only possible string left that the switched-on variable
could match, we invoke the new operation offset_str_eq(N, A, B).
By using the operation, the compiler is asserting that the first N
code units of A and B are equal, and the operation tests whether
the remaining code units are equal as well. The non-C backends,
for which this restricted test is hard or impossible to test efficiently,
can implement this op simply by comparing the WHOLE of A and B.
This is slightly wasteful, in that the first N code units have already
been tested and found to be equal by the trie nodes above, but
it *will* work, and it will almost certainly be faster than the alternatives.

While working on this diff; I found that the way mlds_to_{cs,java,managed}.m
handle writing out binops is screwed up. Once this diff is committed,
someone should fix these, along the lines of the way that this diff
fixes mlds_to_c.m: by making the code a direct switch on the binop,
as opposed to the current if-then-else chain, which is VERY vulnerable
to handling new binops incorrectly.

Zoltan.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Log.trie
Type: application/octet-stream
Size: 5316 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20150223/b4108a15/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DIFF.trie
Type: application/octet-stream
Size: 181941 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20150223/b4108a15/attachment-0001.obj>


More information about the reviews mailing list