[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | maranget@y... |
| Subject: | Re: [Caml-list] Converting variants with only constant constructors to integers |
> Luc Maranget wrote: > > Of course, if you have the following: > > > > > > type t = A | B | C > > > let int_of_t = function > > > A -> 0 > > > | B -> 1 > > > | C -> 2 > > > > > > Then in fact I believe that the compiler already converts that to a > > > hashtable lookup instead of a sequence of jumps.. > > > > The compiler does not convert the above code to 'hashtable lookup'. > > Is there a point where the compiler does do a table lookup for matches > rather than jumps or have I clearly just dreamt that? :o) > > > David As far as I know the compiler always output jumps for matches. Those jumps can be conditional jumps, or indirect jumps. For instance in the case of your code, ther will be two condional jumps (ocamlopt) With a bigger example, say | A -> 0 ... | Z -> 25 It is likely that you get a table of addresses indexed by constructor numbers. -- Luc