Re: Are constructors matched against using "switch" or chained if-else

2022-02-22 Thread David Feuer
That answer (which I did indeed write once upon a time) is somewhat incomplete. Case matches on Ints actually work in about three different ways: 1. Linear search 2. Binary search 3. Jump table There's some amount of mix and match available for gappy things. I don't know all the details. As for

Re: Are constructors matched against using "switch" or chained if-else

2022-02-22 Thread Clinton Mead
David, A random google search has revealed this StackOverflow answer , presumably by yourself or your evil twin, which mentions a binary search being performed. However the particular case you mention is a case match on "Ints", which are far from a

Re: Are constructors matched against using "switch" or chained if-else

2022-02-22 Thread David Feuer
You can ask, but someone else will have to answer. Sorry. On Tue, Feb 22, 2022 at 9:52 PM Clinton Mead wrote: > > Thanks David. Can I ask why? Is it because the first constructor is treated > specially? (perhaps because it has zeroed tag bits)? Or is it just because > there's always an if/else

Re: Are constructors matched against using "switch" or chained if-else

2022-02-22 Thread Clinton Mead
Thanks David. Can I ask why? Is it because the first constructor is treated specially? (perhaps because it has zeroed tag bits)? Or is it just because there's always an if/else chain in order of the constructor definition regardless of the order of the case statement so the higher up the list the

Re: Are constructors matched against using "switch" or chained if-else

2022-02-22 Thread David Feuer
I can answer one of your questions for sure: the order of your case branches doesn't matter at all. However, the order of the data constructors in the type declaration does matter. Put your most likely one first. On Tue, Feb 22, 2022, 9:09 PM Clinton Mead wrote: > Hi All > > I'm developing an

Are constructors matched against using "switch" or chained if-else

2022-02-22 Thread Clinton Mead
Hi All I'm developing an unbounded integer type, which I won't go into the details here but in some circumstances has better performance than the standard "Integer". Anyway, whilst there are complex cases, the most common case is a standard machine int multiplication. Hence I want the type to